Advertisement
vborislavova

10. Ski Trip - Conditional Statements Advanced

Feb 24th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function skiTrip(input) {
  2.     let daysToStay  = Number(input.shift());
  3.     let typeOfRoom  = input.shift();
  4.     let rating = input.shift();
  5.  
  6.     let stayPrice = 0;
  7.     let discount = 0;
  8.     let discountRate = 0;
  9.  
  10.     if (typeOfRoom == "room for one person") {
  11.       stayPrice = (daysToStay - 1) * 18.00;
  12.       if (rating == "positive"){
  13.                 discountRate = stayPrice + (stayPrice * 0.25);
  14.                 console.log(discountRate.toFixed(2));
  15.       } else {
  16.                 discountRate = stayPrice - (stayPrice * 0.10);
  17.                 console.log(discountRate.toFixed(2));
  18.       }    
  19.        
  20.     } else if (typeOfRoom == "apartment") {
  21.         stayPrice = (daysToStay - 1) * 25.00;
  22.         if (daysToStay < 10) {
  23.             discount = stayPrice - (stayPrice * 0.30);
  24.             if (rating == "positive"){
  25.                 discountRate = discount + (discount * 0.25);
  26.                 console.log(discountRate.toFixed(2));
  27.             } else {
  28.                 discountRate = discount - (discount * 0.10);
  29.                  console.log(discountRate.toFixed(2));
  30.             }
  31.          
  32.         } else if (daysToStay >= 10 && daysToStay <= 15) {
  33.             discount = stayPrice - (stayPrice * 0.35);
  34.             if (rating == "positive"){
  35.                 discountRate = discount + (discount * 0.25);
  36.                 console.log(discountRate.toFixed(2));
  37.             } else {
  38.                 discountRate = discount - (discount * 0.10);
  39.                 console.log(discountRate.toFixed(2));
  40.             }
  41.         } else {
  42.             discount = stayPrice - (stayPrice * 0.50);
  43.             if (rating == "positive"){
  44.                 discountRate = discount + (discount * 0.25);
  45.                 console.log(discountRate.toFixed(2));
  46.             } else {
  47.                 discountRate = discount - (discount * 0.10);
  48.                 console.log(discountRate.toFixed(2));
  49.             }
  50.         }
  51.      } else if (typeOfRoom == "president apartment") {
  52.         stayPrice = (daysToStay - 1) * 35.00;
  53.         if (daysToStay < 10) {
  54.             discount = stayPrice - (stayPrice * 0.10);
  55.             if (rating == "positive"){
  56.                 discountRate = discount + (discount * 0.25);
  57.                 console.log(discountRate.toFixed(2));
  58.             } else {
  59.                 discountRate = discount - (discount * 0.10);
  60.                 console.log(discountRate.toFixed(2));
  61.             }
  62.          
  63.         } else if (daysToStay >= 10 && daysToStay <= 15) {
  64.             discount = stayPrice - (stayPrice * 0.15);
  65.             if (rating == "positive"){
  66.                 discountRate = discount + (discount * 0.25);
  67.                 console.log(discountRate.toFixed(2));
  68.             } else {
  69.                 discountRate = discount - (discount * 0.10);
  70.                 console.log(discountRate.toFixed(2));
  71.             }
  72.         } else {
  73.             discount = stayPrice - (stayPrice * 0.20);
  74.             if (rating == "positive"){
  75.                 discountRate = discount + (discount * 0.25);
  76.                 console.log(discountRate.toFixed(2));
  77.             } else {
  78.                 discountRate = discount - (discount * 0.10);
  79.                 console.log(discountRate.toFixed(2));
  80.             }
  81.         }
  82.     }  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement