Разлика между кодовете
Здравейте,
Някой може ли да помогне да ми каже каква е разликата между следните 2 решения на задачата "Лодка за риболов". Двете решения винаги дават верен резултат в конзолата, но в системата единият код му дава 60/100, а другият 100/100.
Точки - 100/100
function fishingBoat(budgetInput, seasonInput, countFishermenInput){
let budget = Number(budgetInput);
let season = seasonInput;
let countFishermen = Number(countFishermenInput);
let price = 0;
if(season === "Winter"){
price = 2600;
} else if(season === "Spring"){
price = 3000;
} else {
price = 4200;
}
if(countFishermen <= 6){
price *= 0.9;
} else if(countFishermen >= 7 && countFishermen <= 11){
price *= 0.85
} else if(countFishermen >= 12){
price *= 0.75;
}
if(countFishermen % 2 === 0 && season != "Autumn"){
price *= 0.95;
}
if(budget >= price){
let left = budget - price;
console.log(`Yes! You have ${left.toFixed(2)} leva left.`);
} else {
let need = price - budget;
console.log(`Not enough money! You need ${need.toFixed(2)} leva.`);
}
}
Точки - 60/100
function fishingBoat(budgetInput, seasonInput, countFishermenInput){
let budget = Number(budgetInput);
let season = seasonInput;
let countFishermen = Number(countFishermenInput);
let boatPrice = 0;
let discountForCount = 0;
let discountForCountAndNotAutumn = 0;
let finalPrice = 0;
if( countFishermen % 2 == 0 && season !== "Autumn"){
discountForCountAndNotAutumn = 0.05;
}
if(countFishermen <= 6){
discountForCount = 0.1;
} else if(countFishermen >= 7 & countFishermen <= 11){
discountForCount = 0.15;
} else {
discountForCount = 0.25;
}
let bothDiscounts = discountForCount + discountForCountAndNotAutumn;
if(season === "Winter"){
boatPrice = 2600;
finalPrice = boatPrice - (bothDiscounts * boatPrice);
} else if(season === "Spring"){
boatPrice = 3000;
finalPrice = boatPrice - (bothDiscounts * boatPrice);
} else{
boatPrice = 4200;
finalPrice = boatPrice - (bothDiscounts * boatPrice);
}
let result = Math.abs(budget - finalPrice).toFixed(2);
if(budget >= finalPrice){
console.log(`Yes! You have ${result} leva left.`);
} else {
console.log(`Not enough money! You need ${result} leva.`);
}
}