ALSAVOV

Untitled

Feb 21st, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.11 KB | Source Code | 0 0
  1. function tourAgency(input) {
  2.     let town = input[0];
  3.     let packetType = input[1];
  4.     let isVip = input[2];
  5.     let daySpent = Number(input[3]);
  6.  
  7.     let priceForADay = 0;
  8.     let finalPrice = 0;
  9.  
  10.     let isValid = true;
  11.  
  12.     if (daySpent < 1) {
  13.         console.log("Days must be positive number!");
  14.         isValid = false;
  15.     }
  16.  
  17.     switch (town) {
  18.         case "Bansko":
  19.         case "Borovets":
  20.             switch (packetType) {
  21.                 case "noEquipment":
  22.                     if (isVip === "yes") {
  23.                         priceForADay = 80 * 0.95;
  24.                     } else {
  25.                         priceForADay = 80;
  26.                     }
  27.                     break;
  28.                 case "withEquipment":
  29.                     if (isVip === "yes") {
  30.                         priceForADay = 100 * 0.9;
  31.                     } else {
  32.                         priceForADay = 100;
  33.                     }
  34.                     break;
  35.                 default:
  36.                     console.log("Invalid input!");
  37.                     isValid = false;
  38.             }
  39.             break;
  40.         case "Varna":
  41.         case "Burgas":
  42.             switch (packetType) {
  43.                 case "withBreakfast":
  44.                     if (isVip === "yes") {
  45.                         priceForADay = 130 * 0.88;
  46.                     } else {
  47.                         priceForADay = 130;
  48.                     }
  49.                     break;
  50.                 case "noBreakfast":
  51.                     if (isVip === "yes") {
  52.                         priceForADay = 100 * 0.93;
  53.                     } else {
  54.                         priceForADay = 100;
  55.                     }
  56.                     break;
  57.                 default:
  58.                     console.log("Invalid input!");
  59.                     isValid = false;
  60.             }
  61.             break;
  62.         default:
  63.             console.log("Invalid input!");
  64.             isValid = false;
  65.     }
  66.  
  67.     if (isValid) {
  68.         finalPrice = priceForADay * daySpent;
  69.         console.log(
  70.             `The price is ${finalPrice.toFixed(2)}lv! Have a nice time!`
  71.         );
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment