Programming Basic with JavaScript
Може ли примерно решение на задача 5-Лодка за риболов от упражненията?
Благодаря предварително.
Може ли примерно решение на задача 5-Лодка за риболов от упражненията?
Благодаря предварително.
Това е код за задачата на Java, ще ти помогне да се ориентираш :-) Успех
https://pastebin.com/DjHGh632
Здрасти, ето и още едно примерно решение:
function fishingBoat(input) {
let budget = Number(input.shift());
let season = input.shift();
let fishermenCount = Number(input.shift());
let price;
if (season == "Spring") {
if (fishermenCount <= 6) {
price = 2700;
} else if (fishermenCount >= 7 && fishermenCount <= 11) {
price = 2550;
} else {
price = 2250;
}
} else if (season == "Summer" || season == "Autumn") {
if (fishermenCount <= 6) {
price = 3780;
} else if (fishermenCount >= 7 && fishermenCount <= 11) {
price = 3570;
} else {
price = 3150;
}
} else {
if (fishermenCount <= 6) {
price = 2340;
} else if (fishermenCount >= 7 && fishermenCount <= 11) {
price = 2210;
} else {
price = 1950;
}
}
if (fishermenCount % 2 == 0 && season != "Autumn") {
price = price - 0.05 * price;
} else {
price = price;
}
let resto = Math.abs(budget - price);
if (budget >= price) {
console.log(`Yes! You have ${resto.toFixed(2)} leva left.`);
} else {
console.log(`Not enough money! You need ${resto.toFixed(2)} leva.`);
}
}
Споделям ти моя код, дано е полезно (макар и дълъг):
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.`)
}
}
Благодаря.