borisova936935

Untitled

Oct 26th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function travelAgency(input) {
  2.  
  3.     let town = input[0];
  4.     let packageType = input[1];
  5.     let vip = input[2];
  6.     let days = Number(input[3]);
  7.  
  8.     let price = 0;
  9.  
  10.     if (town === "Bansko" || town === "Borovets") {
  11.         if (packageType === "withEquipment") {
  12.             price = 100;
  13.             if (vip === "yes") {
  14.                 price -= price * 0.10;
  15.             }
  16.         } else if (packageType === "noEquipment") {
  17.             price = 80;
  18.             if (vip === "yes") {
  19.                 price -= price * 0.05;
  20.             }
  21.         }
  22.     } else if (town === "Varna" || town === "Burgas") {
  23.         if (packageType === "withBreakfast") {
  24.             price = 130;
  25.             if (vip === "yes") {
  26.                 price -= price * 0.12;
  27.             }
  28.         } else if (packageType === "noBreakfast") {
  29.             price = 100;
  30.             if (vip === "yes") {
  31.                 price -= price * 0.07;
  32.             }
  33.         }
  34.     }
  35.  
  36.     let sum = days * price;
  37.  
  38.     if (days < 1) {
  39.         console.log("Days must be positive number!");
  40.  
  41.     } else if (town !== "Bansko" && town !== "Borovets" && town !== "Varna"
  42.         && town !== "Burgas" || packageType !== "withEquipment" && packageType
  43.         !== "noEquipment" && packageType !== "withBreakfast" && packageType
  44.         !== "noBreakfast") {
  45.         console.log("Invalid input!");
  46.  
  47.     } else console.log(`The price is ${sum.toFixed(2)}lv! Have a nice time!`);
  48.  
  49. }
  50. travelAgency(["Gabrovo",
  51. "noBreakfast",
  52. "no",
  53. "3"])
Advertisement
Add Comment
Please, Sign In to add comment