Guest User

Travel Agency

a guest
May 9th, 2020
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function travelAgency([type1, type2, type3, arg1]) {
  2.     let town = type1;
  3.     let package = type2;
  4.     let discount = type3;
  5.     let days = Number(arg1);
  6.  
  7.     if(town === "Bansko" || town === "Borovets") {
  8.         if(package === "withEquipment") {
  9.             switch(discount) {
  10.                 case "yes": price = 100 * 0.9; break;
  11.                 case "no": price = 100; break
  12.             }
  13.         }else if(package === "noEquipment") {
  14.             switch(discount) {
  15.                 case "yes": price = 80 * 0.95; break;
  16.                 case "no": price = 80; break
  17.             }
  18.         }      
  19.     } else if(town === "Varna" || town === "Burgas") {
  20.         if(package === "withBreakfast") {
  21.             switch(discount) {
  22.                 case "yes": price = 130 * 0.88; break;
  23.                 case "no": price = 130; break;
  24.             }
  25.         } else if(package === "noBreakfast") {
  26.             switch(discount) {
  27.                 case "yes": price = 100 * 0.93; break;
  28.                 case "no": price = 100; break;          
  29.             }
  30.         }
  31.     } else {
  32.         console.log(`Invalid input!`);
  33.     }
  34.  
  35.     if(days >= 1 && days <=7) {
  36.         cost = price * days;
  37.     } else if(days > 7) {
  38.         cost = price * (days - 1);
  39.     } else if(days < 1) {
  40.         console.log(`Days must be positive number!`);
  41.     }
  42.       console.log(`The price is ${cost.toFixed(2)}lv! Have a nice time!`);
  43. }
  44.  
  45. travelAgency(["Gabrovo", "noBreakfast", "no", 3])
Add Comment
Please, Sign In to add comment