Daily Coding Challenge - Space Week Day 7: Launch Fuel

Tell us what’s happening:

Hi, I got the failed test:
3. launchFuel(243) should return 60.7.
by the fact that it returns 60.6

function launchFuel(payload) {
let fuel = +(payload / 5).toFixed(1);
if (fuel < 1) return fuel;
return fuel + launchFuel(fuel);
}
console.log(launchFuel(243)) // should return 60.7.

What is wrong here?

Your code so far

function launchFuel(payload) {
    let fuel = Math.round(payload / 5 * 10) / 10;
    if (fuel < 1) return fuel;
    return fuel + launchFuel(fuel);
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Daily Coding Challenge - Space Week Day 7: Launch Fuel
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-10-10

probably rounding before doing the sum each time is removing some mass from the final calculation, can you consider a iterative approach maybe?

1 Like