Проблем със задача 01. Guinea Pig от 04. Programming Fundamentals Mid Exam js
Конзолата дава верни отговори а, Judge - грешка
Условие на задачата https://pastebin.com/5DMHiZwn
Моето решение :
function solve(foodKg, hayKg, coverKg, weight){
let foodGr = foodKg * 1000;
let hayGr = hayKg * 1000;
let coverGr = coverKg * 1000;
let weightGr = weight * 1000;
let excessFood = 0;
let excessHay = 0;
let excessCover = 0;
let isEnough = true;
let counter = 0;
for (i = 1; i <= 30; i++) {
counter++;
if (counter % 1 === 0) {
foodGr -= 300;
excessFood--
}
if (counter % 2 === 0) {
hayGr -= foodGr * 0.05;
excessHay--
}
if (counter % 3 === 0) {
coverGr -= weightGr / 3
excessCover--
}
if(foodGr < 0 || hayGr < 0 || coverGr < 0){
isEnough = false;
console.log("Merry must go to the pet store!")
break;
}
}
let foodBackKg = foodGr / 1000;
let hayBackKg = hayGr / 1000;
let coverBackKg = coverGr / 1000;
if(isEnough){
console.log(`Everything is fine! Puppy is happy! Food: ${foodBackKg.toFixed(2)}, Hay: ${hayBackKg.toFixed(2)}, Cover: ${coverBackKg.toFixed(2)}`)
}
}
solve(10, 5, 5.2, 1)
solve(1, 1.5, 3, 1.5)
Thank you very much :)