PowerCell46

Travel agency JS

Oct 11th, 2022
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function travelAgency(input) {
  2. let city = input[0];
  3. let typeOfThePackage = input[1];
  4. let vip = input[2];
  5. let numberOfDays = input[3];
  6.  
  7. let priceForADay = 0;
  8. let vipDiscount = 0;
  9.  
  10. if(numberOfDays < 1 ) {
  11.     console.log("Days must be positive number!");
  12. } else {
  13.  
  14. switch(city) {
  15.     case "Bansko":
  16.     switch(typeOfThePackage) {
  17.     case "withEquipment": priceForADay = 100; vipDiscount = 10; break;
  18.     case "noEquipment": priceForADay = 80; vipDiscount = 5; break;
  19.     default: console.log("Invalid input!"); break;
  20.     } break;
  21.  
  22.     case "Borovets":
  23.         switch(typeOfThePackage) {
  24.             case "withEquipment": priceForADay = 100; vipDiscount = 10; break;
  25.             case "noEquipment": priceForADay = 80; vipDiscount = 5; break;
  26.             default: console.log("Invalid input!"); break;
  27.         } break;
  28.  
  29.     case "Varna":
  30.     switch(typeOfThePackage) {
  31.         case "withBreakfast": priceForADay = 130; vipDiscount = 12; break;
  32.         case "noBreakfast": priceForADay = 100; vipDiscount = 7; break;
  33.         default: console.log("Invalid input!"); break;
  34.     } break;
  35.  
  36.     case "Burgas":
  37.         switch(typeOfThePackage) {
  38.             case "withBreakfast": priceForADay = 130; vipDiscount = 12; break;
  39.             case "noBreakfast": priceForADay = 100; vipDiscount = 7; break;
  40.             default: console.log("Invalid input!"); break;
  41.         } break;
  42.  
  43.     default: console.log("Invalid input!"); break;
  44. }
  45.  
  46. if(numberOfDays > 7) {
  47. numberOfDays = numberOfDays - 1;
  48. }
  49. let finalFinalPrice = 0;
  50. let finalPrice = priceForADay * numberOfDays;
  51.  
  52. if(vip === "yes") {
  53. finalFinalPrice = finalPrice - ((finalPrice / 100) * vipDiscount);
  54. } else if(vip === "no") {
  55. finalFinalPrice = finalPrice;
  56. }
  57.  
  58. if(finalFinalPrice > 0) {
  59.     console.log("The price is " + finalFinalPrice.toFixed(2) + "lv! Have a nice time!");
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment