Guest User

Untitled

a guest
Jan 31st, 2019
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function boat(input) {
  2.  
  3.     let budget = Number(input.shift());
  4.  
  5.     let season = input.shift();
  6.  
  7.     let fisherCount = Number(input.shift());
  8.  
  9.  
  10.  
  11.     let discount = 0;
  12.  
  13.     let finalPrice = 0;
  14.  
  15.  
  16.  
  17.     switch (season) {
  18.  
  19.         case 'Spring': boatPrice = 3000;
  20.  
  21.             break;
  22.  
  23.         case 'Summer': boatPrice = 4200;
  24.  
  25.             break;
  26.  
  27.         case 'Autumn': boatPrice = 4200;
  28.  
  29.             break;
  30.  
  31.         case 'Winter': boatPrice = 2600;
  32.  
  33.             break;
  34.  
  35.         default: '';
  36.  
  37.  
  38.  
  39.     }
  40.  
  41.  
  42.  
  43.     if (fisherCount <= 6) {
  44.  
  45.         discount = 0.10;
  46.  
  47.     } else if (fisherCount <= 11) {
  48.  
  49.         discount = 0.15;
  50.  
  51.     } else {
  52.  
  53.         discount = 0.25;
  54.  
  55.     }
  56.  
  57.     //changed code
  58.     finalPrice = boatPrice - (boatPrice * discount);
  59.  
  60.     if (fisherCount % 2 == 0 && season !== 'Autumn') {
  61.  
  62.         finalPrice *= 0.95;
  63.  
  64.     }
  65.     //changed code
  66.    
  67.     if (budget >= finalPrice) {
  68.  
  69.         console.log(`Yes! You have ${(budget - finalPrice).toFixed(2)} leva left.`)
  70.  
  71.     } else {
  72.  
  73.         console.log(`Not enough money! You need ${Math.abs(budget - finalPrice).toFixed(2)} leva.`)
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment