Advertisement
Spocoman

09. Ski Trip

Dec 20th, 2021 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. РЕШЕНИЕ С IF-ELSE:
  2.  
  3. function skiTrip(input) {
  4.  
  5.     let night = Number(input[0]) - 1;
  6.     let room = input[1];
  7.     let rating = input[2];
  8.     let priceForRoom = 18;
  9.     let priceForApartment = 25;
  10.     let priceForPresidentApartment = 35;
  11.     let totalSum = 0;
  12.  
  13.     if (room == "room for one person") {
  14.         totalSum = priceForRoom * night;
  15.     } else if (room == "apartment") {
  16.         totalSum = priceForApartment * night;
  17.  
  18.         if (night < 10) {
  19.             totalSum *= 0.70;
  20.         } else if (night >= 10 && night < 15) {
  21.             totalSum *= 0.65;
  22.         } else if (night >= 15) {
  23.             totalSum *= 0.5;
  24.         }
  25.     } else if (room == "president apartment") {
  26.         totalSum = priceForPresidentApartment * night;
  27.  
  28.         if (night < 10) {
  29.             totalSum *= 0.90;
  30.         } else if (night >= 10 && night < 15) {
  31.             totalSum *= 0.85;
  32.         } else if (night >= 15) {
  33.             totalSum *= 0.80;
  34.         }
  35.     }
  36.  
  37.     if (rating == "positive") {
  38.         totalSum *= 1.25;
  39.     } else if (rating == "negative") {
  40.         totalSum *= 0.90;
  41.     }
  42.     console.log(`${totalSum.toFixed(2)}`);
  43. }
  44.  
  45.  
  46. РЕШЕНИЕ СЪС SWITCH I IF-ELSE:
  47.  
  48. function skiTrip(input) {
  49.  
  50.     let night = Number(input[0]) - 1;
  51.     let room = input[1];
  52.     let rating = input[2];
  53.     let priceForRoom = 18;
  54.     let priceForApartment = 25;
  55.     let priceForPresidentApartment = 35;
  56.     let totalSum = 0;
  57.  
  58.     switch (room){
  59.         case "room for one person":
  60.             totalSum = priceForRoom * night;
  61.             break;
  62.  
  63.     case "apartment":
  64.         totalSum = priceForApartment * night;
  65.         if (night < 10) {
  66.             totalSum *= 0.70;
  67.         } else if (night >= 10 && night < 15) {
  68.             totalSum *= 0.65;
  69.         } else if (night >= 15) {
  70.             totalSum *= 0.5;
  71.         }
  72.         break;
  73.  
  74.     case "president apartment":
  75.         totalSum = priceForPresidentApartment * night;
  76.         if (night < 10) {
  77.             totalSum *= 0.90;
  78.         } else if (night >= 10 && night < 15) {
  79.             totalSum *= 0.85;
  80.         } else if (night >= 15) {
  81.             totalSum *= 0.80;
  82.         }
  83.         break;
  84.     }
  85.    
  86.     if (rating == "positive") {
  87.         totalSum *= 1.25;
  88.     } else if (rating == "negative") {
  89.         totalSum *= 0.90;
  90.     }
  91.     console.log(`${totalSum.toFixed(2)}`);
  92. }
  93.  
  94.  
  95. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  96.  
  97. function skiTrip(input) {
  98.     let night = Number(input[0]) - 1;
  99.     let room = input[1];
  100.     let rating = input[2];
  101.  
  102.     let totalSum = ((room == "room for one person" ? 18 :
  103.         room == "apartment" ? (25 * (night < 10 ? 0.7 : night >= 15 ? 0.5 : 0.65)) :
  104.             (35 * (night < 10 ? 0.9 : night >= 15 ? 0.8 : 0.85))) * night) * (rating == "positive" ? 1.25 : 0.9);
  105.  
  106.     console.log(`${totalSum.toFixed(2)}`);
  107. }
  108.  
  109.  
  110. ИЛИ ТАРИКАТСКАТА:)
  111.  
  112. function skiTrip(input) {
  113.  
  114.     let night = Number(input[0]) - 1;
  115.  
  116.     console.log(`${(((input[1] == "room for one person" ? 18 :
  117.         input[1] == "apartment" ? (25 * (night < 10 ? 0.7 : night >= 15 ? 0.5 : 0.65)) :
  118.         (35 * (night < 10 ? 0.9 : night >= 15 ? 0.8 : 0.85))) * night) * (input[2] == "positive" ? 1.25 : 0.9)).toFixed(2)}`);
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement