Spring Vacation Trip
https://pastebin.com/9qSzGfGL
88 / 100 точки. Може ли някой съвет? Благодаря!
https://pastebin.com/9qSzGfGL
88 / 100 точки. Може ли някой съвет? Благодаря!
Code was fine, the only thing that had to be changed was the position of the break-validation towards the end of the loop and to remove the output message from the break-validation to avoid printing the message twice.
Refactored for-loop:
for (let i = 1; i <= daysOfTrip; i++) {
// if (currentExpenses > budget) {
// console.log(
// `Not enough money to continue the trip. You need ${diff}$ more.`
// );
// break;
// }
let dailyFuel = priceFuelKm * travelledDistanceKmDaily;
currentExpenses += dailyFuel;
if (i % 3 === 0 || i % 5 === 0) {
currentExpenses += currentExpenses * 0.4;
}
if (i % 7 === 0) {
currentExpenses -= currentExpenses / groupPeople;
}
travelledDistanceKmDaily = Number(input.shift());
diff = Math.abs(budget - currentExpenses).toFixed(2);
if (currentExpenses > budget) {
// console.log(
// `Not enough money to continue the trip. You need ${diff}$ more.`
// );
break;
}
}
Thank you!!! It's all fine now :)