Programming Basic with JavaScript
Може ли примерно решение на задача 5-Лодка за риболов от упражненията?
Благодаря предварително.
Може ли примерно решение на задача 5-Лодка за риболов от упражненията?
Благодаря предварително.
Споделям ти моя код, дано е полезно (макар и дълъг):
function fishingBoat(input) {
let budget = Number(input.shift());
let season = input.shift();
let fisherMen = Number(input.shift());
let rent;
let whatsLeft;
switch (season) {
case "Spring":
rent = 3000;
if (fisherMen <= 6) {
rent = rent - (rent * 0.1);
} else if (fisherMen > 6 && fisherMen <= 11) {
rent = rent - (rent * 0.15);
} else {
rent = rent - (rent * 0.25);
}
break;
case "Summer":
rent = 4200;
if (fisherMen <= 6) {
rent = rent - (rent * 0.1);
} else if (fisherMen > 6 && fisherMen <= 11) {
rent = rent - (rent * 0.15);
} else {
rent = rent - (rent * 0.25);
}
break;
case "Autumn":
rent = 4200;
if (fisherMen <= 6) {
rent = rent - (rent * 0.1);
} else if (fisherMen > 6 && fisherMen <= 11) {
rent = rent - (rent * 0.15);
} else {
rent = rent - (rent * 0.25);
}
break;
case "Winter":
rent = 2600;
if (fisherMen <= 6) {
rent = rent - (rent * 0.1);
} else if (fisherMen > 6 && fisherMen <= 11) {
rent = rent - (rent * 0.15);
} else {
rent = rent - (rent * 0.25);
}
break;
default:
break;
}
if (season == "Autumn") {
if (budget >= rent) {
whatsLeft = budget - rent;
} else {
whatsLeft = rent - budget;
}
} else {
if (fisherMen % 2 == 0) {
rent = rent - (rent * 0.05);
if (budget >= rent) {
whatsLeft = budget - rent;
} else {
whatsLeft = rent - budget;
}
} else {
if (budget >= rent) {
whatsLeft = budget - rent;
} else {
whatsLeft = rent - budget;
}
}
}
if (budget >= rent) {
console.log(`Yes! You have ${whatsLeft.toFixed(2)} leva left.`);
} else {
console.log(`Not enough money! You need ${whatsLeft.toFixed(2)} leva.`)
}
}