Advertisement
Spocoman

Excursion Calculator

May 29th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function excursionCalculator(input) {
  2.     let people = Number(input[0]);
  3.     let season = input[1];
  4.     let price = 0;
  5.  
  6.     if (season == "spring") {
  7.         if (people <= 5) {
  8.             price = 50;
  9.         } else {
  10.             price = 48;
  11.         }
  12.     } else if (season == "summer") {
  13.         if (people <= 5) {
  14.             price = 48.50;
  15.         } else {
  16.             price = 45;
  17.         }
  18.     } else if (season == "autumn") {
  19.         if (people <= 5) {
  20.             price = 60;
  21.         } else {
  22.             price = 49.50;
  23.         }
  24.     } else if (season == "winter") {
  25.         if (people <= 5) {
  26.             price = 86;
  27.         } else {
  28.             price = 85;
  29.         }
  30.     }
  31.  
  32.     if (season == "summer") {
  33.         price *= 0.85;
  34.     } else if (season == "winter") {
  35.         price *= 1.08;
  36.     }
  37.  
  38.     console.log(`${(price * people).toFixed(2)} leva.`);
  39. }
  40.  
  41.  
  42. РЕШЕНИЕ СЪС SWITCH И ТЕРНАРЕН ОПЕРАТОР:
  43.  
  44. function excursionCalculator(input) {
  45.     let people = Number(input[0]);
  46.     let season = input[1];
  47.     let price = 0;
  48.  
  49.     switch (season) {
  50.         case "spring":
  51.             price = people <= 5 ? 50 : 48;
  52.             break;
  53.  
  54.         case "summer":
  55.             price = people <= 5 ? 48.50 : 45;
  56.             break;
  57.  
  58.         case "autumn":
  59.             price = people <= 5 ? 60 : 49.50;
  60.             break;
  61.  
  62.         case "winter":
  63.             price = people <= 5 ? 86 : 85;
  64.             break;
  65.     }
  66.  
  67.     price *= season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1;
  68.  
  69.     console.log(`${(price * people).toFixed(2)} leva.`);
  70. }
  71.  
  72.  
  73. РЕШЕНИЕ САМО С ТЕРНАРЕН ОПЕРАТОР:
  74.  
  75. function excursionCalculator(input) {
  76.     let people = Number(input[0]);
  77.     let season = input[1];
  78.  
  79.     let price = (season == "spring" ? (people <= 5 ? 50 : 48) :
  80.                 season == "summer" ? (people <= 5 ? 48.50 : 45) :
  81.                 season == "autumn" ? (people <= 5 ? 60 : 49.50) :
  82.                 season == "winter" ? (people <= 5 ? 86 : 85) : 0) *
  83.                 (season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1) * people;
  84.  
  85.     console.log(`${price.toFixed(2)} leva.`);
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement