Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fishingBoat(input){
- let budget = Number(input[0]);
- let season = input[1];
- let people = Number(input[2]);
- let sum = 0;
- switch (season) {
- case "Spring":
- sum = 3000;
- break;
- case "Summer":
- case "Autumn":
- sum = 4200;
- break;
- case "Winter":
- sum = 2600;
- break;
- }
- if (people <= 6) {
- sum *= 0.9;
- } else if (people > 6 && people <= 11) {
- sum *= 0.85;
- } else {
- sum *= 0.75;
- }
- if (people % 2 === 0 && season !== "Autumn") {
- sum *= 0.95;
- }
- if (budget >= sum) {
- console.log(`Yes! You have ${(budget - sum).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${(sum - budget).toFixed(2)} leva.`);
- }
- }
- РЕШЕНИЕ С IF ELSE ЛЕКО ТАРИКАТСКАТА:
- function fishingBoat(input) {
- let budget = Number(input[0]);
- let season = input[1];
- let people = Number(input[2]);
- let sum = 4200;
- if (season === "Spring") {
- sum = 3000;
- } else if (season === "Winter") {
- sum = 2600;
- }
- if (people <= 6) {
- sum *= 0.9;
- } else if (people > 11) {
- sum *= 0.75;
- } else {
- sum *= 0.85;
- }
- if (people % 2 === 0 && season !== "Autumn") {
- sum *= 0.95;
- }
- if (budget >= sum) {
- console.log(`Yes! You have ${(budget - sum).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${(sum - budget).toFixed(2)} leva.`);
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function FishingBoat(input) {
- let budget = Number(input[0]);
- let season = input[1];
- let people = Number(input[2]);
- budget -= ((season === "Spring" ? 3000 : season === "Winter" ? 2600 : 4200) *
- (people <= 6 ? 0.9 : people > 11 ? 0.75 : 0.85) *
- (people % 2 === 0 && season !== "Autumn" ? 0.95 : 1));
- console.log(budget >= 0 ? `Yes! You have ${budget.toFixed(2)} leva left.` :
- `Not enough money! You need ${Math.abs(budget).toFixed(2)} leva.`);
- }
Add Comment
Please, Sign In to add comment