Every weekend someone asks us the same thing before picking up a self-drive car: "How much will this trip actually cost?" The rental is only part of it. Fuel, tolls and the odd parking fee add up, and most people guess.
So here is a small, dependency-free JavaScript function that turns a route into a rough budget. Paste it into your browser console or a Node REPL and change the numbers for your own trip.
The idea
A road-trip budget is mostly four things:
- Rental - days x daily rate
- Fuel - total km / mileage x fuel price
- Tolls - a fixed amount per route
- Buffer - parking, snacks and surprises, as a percentage
The code
function tripBudget({ days, dailyRate, totalKm, kmPerLitre, fuelPrice, tolls = 0, bufferPct = 10 }) {
const rental = days * dailyRate;
const fuel = (totalKm / kmPerLitre) * fuelPrice;
const subtotal = rental + fuel + tolls;
const buffer = subtotal * (bufferPct / 100);
const total = Math.round(subtotal + buffer);
return {
rental: Math.round(rental),
fuel: Math.round(fuel),
tolls,
buffer: Math.round(buffer),
total,
};
}
// Example: a 2-day hill weekend in a hatchback.
// Every number below is a placeholder - replace it with your own.
console.table(tripBudget({
days: 2,
dailyRate: 2000, // your quoted daily rate
totalKm: 300, // round trip, from your map app
kmPerLitre: 15, // check the car's real-world mileage
fuelPrice: 95, // today's local petrol price
tolls: 200, // from your map app's toll estimate
bufferPct: 10,
}));
console.table prints a neat breakdown, so you can see straight away whether fuel or rental is the bigger slice.
Comparing cars in one go
The useful part is running the same trip for different cars. A bigger SUV costs more per day and drinks more fuel, but splits better across six people.
const trip = { days: 2, totalKm: 300, fuelPrice: 95, tolls: 200 };
const cars = [
{ name: 'Hatchback', dailyRate: 2000, kmPerLitre: 15 },
{ name: '7-seater', dailyRate: 3200, kmPerLitre: 12 },
{ name: 'SUV 4x4', dailyRate: 4500, kmPerLitre: 10 },
];
console.table(cars.map(c => ({
car: c.name,
...tripBudget({ ...trip, ...c }),
})));
Divide total by the number of travellers and the "cheap" option is not always the cheapest per head.
Things the script does not know
- Hill driving lowers real mileage, so knock 15-25% off the brochure figure for mountain routes.
- Fuel prices change, so look up the day's rate before you leave.
- Rental terms differ - kilometre limits, fuel policy and security deposits are worth reading before you book.
Wrapping up
It is a ten-minute script, but it stops the "we'll figure it out on the way" budgeting that ruins half the fun of a road trip. Fork it, add a split-the-bill line, or wire it to a form.
We run a self-drive rental desk in Sector 3, Chandigarh, and built this after one too many customers asked us for a quick estimate. If you are planning a drive from here, our customers call us the best car rental service in chandigarh for doorstep delivery and transparent daily rates - or ask on +91 98150 02525.
Top comments (0)