gskorchev

fishing boat

Jan 29th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fishingBoat(input) {
  2.     let groupBudget = Number(input.shift());
  3.     let season = input.shift();
  4.     let fishersCount = Number(input.shift());
  5.     let discount = 0;
  6.     let currentprice = 0;
  7.     let rent;
  8.     switch (season) {
  9.         case "Spring":
  10.             rent = 3000;
  11.             if (fishersCount <= 6) {
  12.                 discount = 0.1;
  13.                 currentprice = rent - (rent * discount);
  14.             } else if (fishersCount <= 11) {
  15.                 discount = 0.15;
  16.                 currentprice = rent - (rent * discount);
  17.             } else if (fishersCount > 11) {
  18.                 discount = 0.25;
  19.                 currentprice = rent - (rent * discount);
  20.             }
  21.             if (fishersCount % 2 == 0) {
  22.                 currentprice = currentprice - (currentprice * 0.05);
  23.             }
  24.             if (groupBudget >= currentprice) {
  25.                 console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
  26.             } else {
  27.                 console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
  28.             };
  29.             break;
  30.         case "Summer":
  31.             rent = 4200;
  32.             if (fishersCount <= 6) {
  33.                 discount = 0.1;
  34.                 currentprice = rent - (rent * discount);
  35.             } else if (fishersCount <= 11) {
  36.                 discount = 0.15;
  37.                 currentprice = rent - (rent * discount);
  38.             } else if (fishersCount > 11) {
  39.                 discount = 0.25;
  40.                 currentprice = rent - (rent * discount);
  41.             }
  42.             if (fishersCount % 2 == 0) {
  43.                 currentprice = currentprice - (currentprice * 0.05);
  44.             }
  45.             if (groupBudget >= currentprice) {
  46.                 console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
  47.             } else {
  48.                 console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
  49.             };
  50.             break;
  51.         case "Autumn":
  52.             rent = 4200;
  53.             if (fishersCount <= 6) {
  54.                 discount = 0.1;
  55.                 currentprice = rent - (rent * discount);
  56.             } else if (fishersCount <= 11) {
  57.                 discount = 0.15;
  58.                 currentprice = rent - (rent * discount);
  59.             } else if (fishersCount > 11) {
  60.                 discount = 0.25;
  61.                 currentprice = rent - (rent * discount);
  62.             }
  63.             if (groupBudget >= currentprice) {
  64.                 console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
  65.             } else {
  66.                 console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
  67.             };
  68.             break;
  69.         case "Winter":
  70.             rent = 2600;
  71.             if (fishersCount <= 6) {
  72.                 discount = 0.1;
  73.                 currentprice = rent - (rent * discount);
  74.             } else if (fishersCount <= 11) {
  75.                 discount = 0.15;
  76.                 currentprice = rent - (rent * discount);
  77.             } else if (fishersCount > 11) {
  78.                 discount = 0.25;
  79.                 currentprice = rent - (rent * discount);
  80.             }
  81.             if (fishersCount % 2 == 0) {
  82.                 currentprice = currentprice - (currentprice * 0.05);
  83.             }
  84.             if (groupBudget >= currentprice) {
  85.                 console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
  86.             } else {
  87.                 console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
  88.             };
  89.             break;
  90.     }
  91. }
  92. fishingBoat([3600, "Autumn", 6]);
Advertisement
Add Comment
Please, Sign In to add comment