Advertisement
zarkoto223

Untitled

Mar 18th, 2024
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tourAgency(input) {
  2.   let city = input[0];
  3.   let extras = input[1];
  4.   let vip = input[2];
  5.   let numberNights = Number(input[3]);
  6.   let pricePerNight = 0;
  7.  
  8.   if (numberNights < 1) {
  9.     console.log("Days must be positive number!");
  10.     return;
  11.   }
  12.  
  13.   if (
  14.     (city !== "Bansko" &&
  15.       city !== "Borovets" &&
  16.       city !== "Varna" &&
  17.       city !== "Burgas") ||
  18.     (extras !== "noEquipment" &&
  19.       extras !== "withEquipment" &&
  20.       extras !== "noBreakfast" &&
  21.       extras !== "withBreakfast")
  22.   ) {
  23.     console.log("Invalid input!");
  24.     return;
  25.   }
  26.   if (numberNights > 7) {
  27.     numberNights -= 1;
  28.   }
  29.  
  30.   if (city === "Bansko" || city === "Borovets") {
  31.     if (extras === "withEquipment") {
  32.       pricePerNight = 100;
  33.       if (vip === "yes") {
  34.         pricePerNight *= 0.9;
  35.       }
  36.     } else {
  37.       pricePerNight = 80;
  38.       if (vip === "yes") {
  39.         pricePerNight *= 0.95;
  40.       }
  41.     }
  42.   } else if (city === "Varna" || city === "Burgas") {
  43.     pricePerNight = 130;
  44.     if (extras === "withBreakfast") {
  45.       pricePerNight = 130;
  46.       if (vip === "yes") {
  47.         pricePerNight *= 0.88;
  48.       }
  49.     } else {
  50.       pricePerNight = 100;
  51.       if (vip === "yes") {
  52.         pricePerNight * 0.93;
  53.       }
  54.     }
  55.   }
  56.   console.log(
  57.     `The price is ${(numberNights * pricePerNight).toFixed(
  58.       2
  59.     )}lv! Have a nice time!`
  60.   );
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement