Advertisement
dabidabidesh

Only switch

Feb 26th, 2020
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fishingBoat0(input) {
  2.  
  3.   let [budget, season, fishermenCount, price, diff] = [+input[0], input[1], +input[2], 0, 0]
  4.  
  5.   switch (season) {
  6.     case 'Spring':
  7.       price = 3000
  8.       break
  9.     case 'Summer':
  10.     case 'Autumn':
  11.       price = 4200
  12.       break
  13.     case 'Winter':
  14.       price = 2600
  15.   }
  16.  
  17.   switch (true) {
  18.     case fishermenCount <= 6:
  19.       price = price - price * 0.1
  20.       break
  21.     case fishermenCount >= 7 && fishermenCount <= 11:
  22.       price = price - price * 0.15
  23.       break
  24.     case fishermenCount >= 12:
  25.       price = price - price * 0.25
  26.   }
  27.  
  28.   switch (true) {
  29.     case (fishermenCount % 2 == 0 && season != 'Autumn'):
  30.       price = price - price * 0.05
  31.   }
  32.  
  33.   diff = (Math.abs(budget - price)).toFixed(2)
  34.  
  35.   switch (true) {
  36.     case (budget >= price):
  37.       result = `Yes! You have ${diff} leva left.`
  38.       break
  39.     default:
  40.       result = `Not enough money! You need ${diff} leva.`
  41.   }
  42.  
  43.   console.log(result)
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement