ALSAVOV

Untitled

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