RV Road Trip Cost Estimator

RV Road Trip Cost Estimator

Plan Your Trip

Your Estimated Cost

Enter your trip details to see the estimated cost.

Customize Cost Data

Please enter valid trip details.

'; return; } let breakdown = {}; // Fuel Cost const gallonsNeeded = distance / selectedRv.mpg; const fuelCost = gallonsNeeded * costData.fuelPricePerGallon; breakdown['Fuel'] = fuelCost; // Campground Cost const campgroundCost = duration * selectedStyle.campgroundCostPerNight; breakdown['Campgrounds'] = campgroundCost; // Food & Activities Cost (duration + 1 day for travel) const foodCost = (duration + 1) * selectedStyle.foodCostPerDay; const activitiesCost = (duration + 1) * selectedStyle.activitiesCostPerDay; breakdown['Food & Groceries'] = foodCost; breakdown['Activities & Entertainment'] = activitiesCost; const totalCost = fuelCost + campgroundCost + foodCost + activitiesCost; renderResults(totalCost, breakdown); } function renderResults(total, breakdown) { let breakdownHTML = '
    '; for (const [key, value] of Object.entries(breakdown)) { breakdownHTML += `
  • ${key}$${value.toFixed(2)}
  • `; } breakdownHTML += '
'; resultsSummary.innerHTML = `

Total Estimated Cost

$${total.toFixed(2)}

Cost Breakdown

${breakdownHTML}
`; } function renderConfig() { configContainer.innerHTML = `

General Costs

ItemCost ($)
Average Fuel Price (per gallon)

RV Fuel Efficiency (MPG)

${costData.rvTypes.map(r => ``).join('')}
RV TypeMiles Per Gallon
${r.name}

Travel Style Daily Costs ($)

${costData.travelStyles.map(s => ` `).join('')}
StyleCampground (per night)Food (per day)Activities (per day)
${s.name}
`; } window.updateConfig = function(element) { const { type, id, prop } = element.dataset; const value = parseFloat(element.value); if (isNaN(value)) return; if (type) { // It's an array item const item = costData[type].find(i => i.id === id); if (item) item[prop] = value; } else { // It's a root property costData[prop] = value; } calculateCost(); } // --- TAB & NAVIGATION --- window.openTab = function(evt, tabName) { const tabContents = document.getElementsByClassName("tab-content"); Array.from(tabContents).forEach(tab => tab.style.display = "none"); const tabButtons = document.getElementsByClassName("tab-btn"); Array.from(tabButtons).forEach(btn => btn.classList.remove("active")); document.getElementById(tabName).style.display = "block"; if (evt) { evt.currentTarget.classList.add("active"); } else { const btnToActivate = Array.from(tabButtons).find(btn => btn.getAttribute('onclick').includes(`'${tabName}'`)); if (btnToActivate) btnToActivate.classList.add("active"); } updateNavButtons(); } window.navigateTabs = function(direction) { const tabs = Array.from(document.querySelectorAll('.tab-btn')); const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active')); let newIndex = (direction === 'next') ? (activeTabIndex + 1) % tabs.length : (activeTabIndex - 1 + tabs.length) % tabs.length; tabs[newIndex].click(); } function updateNavButtons() { const tabs = Array.from(document.querySelectorAll('.tab-btn')); const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active')); document.getElementById('prev-btn').style.visibility = activeTabIndex === 0 ? 'hidden' : 'visible'; document.getElementById('next-btn').style.visibility = activeTabIndex === tabs.length - 1 ? 'hidden' : 'visible'; } // --- PDF DOWNLOAD --- if(downloadPdfBtn) { downloadPdfBtn.addEventListener('click', function() { const { jsPDF } = window.jspdf; const contentToDownload = document.getElementById('results-to-download'); if (!contentToDownload || !document.querySelector('.total-cost')) { console.warn("Please calculate a cost before downloading."); return; } const originalButtonText = downloadPdfBtn.innerHTML; downloadPdfBtn.innerHTML = 'Generating...'; downloadPdfBtn.disabled = true; html2canvas(contentToDownload, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth - 20, imgHeight > 0 ? imgHeight - 20 : 0); pdf.save('RV-Trip-Cost-Estimate.pdf'); }).catch(err => { console.error("Error generating PDF:", err); }).finally(() => { downloadPdfBtn.innerHTML = originalButtonText; downloadPdfBtn.disabled = false; }); }); } // --- INITIALIZATION --- function initializeTool() { populateControls(); calculateCost(); renderConfig(); updateNavButtons(); } initializeTool(); });
Scroll to Top