Advertisement
Spocoman

Cruise Ship

Oct 7th, 2023 (edited)
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cruiseShip(input) {
  2.     let destination = input[0];
  3.     let cabinType = input[1];
  4.     let overnights = Number(input[2]);
  5.  
  6.     let dayPrice = 0;
  7.  
  8.     if (destination == "Mediterranean") {
  9.         if (cabinType == "standard cabin") {
  10.             dayPrice = 27.50;
  11.         } else if (cabinType == "cabin with balcony") {
  12.             dayPrice = 30.20;
  13.         } else {
  14.             dayPrice = 40.50;
  15.         }
  16.     } else if (destination == "Adriatic") {
  17.         if (cabinType == "standard cabin") {
  18.             dayPrice = 22.99;
  19.         } else if (cabinType == "cabin with balcony") {
  20.             dayPrice = 25.00;
  21.         } else {
  22.             dayPrice = 34.99;
  23.         }
  24.     } else {
  25.         if (cabinType == "standard cabin") {
  26.             dayPrice = 23.00;
  27.         } else if (cabinType == "cabin with balcony") {
  28.             dayPrice = 26.60;
  29.         } else {
  30.             dayPrice = 39.80;
  31.         }
  32.     }
  33.  
  34.     let totalSum = dayPrice * 4 * overnights;
  35.     if (overnights > 7) {
  36.         totalSum *= 0.75;
  37.     }
  38.  
  39.     console.log(`Annie\'s holiday in the ${destination} sea costs ${totalSum.toFixed(2)} lv.`);
  40.    return;
  41. }
  42.  
  43. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  44.  
  45. function cruiseShip(input) {
  46.    let destination = input[0];
  47.    let cabinType = input[1];
  48.    let overnights = Number(input[2]);
  49.  
  50.    let dayPrice =
  51.        destination == "Mediterranean" ?
  52.            (cabinType == "standard cabin" ? 27.50 : cabinType == "cabin with balcony" ? 30.20 : 40.50) :
  53.            destination == "Adriatic" ?
  54.                (cabinType == "standard cabin" ? 22.99 : cabinType == "cabin with balcony" ? 25.00 : 34.99) :
  55.                (cabinType == "standard cabin" ? 23.00 : cabinType == "cabin with balcony" ? 26.60 : 39.80);
  56.  
  57.    let totalSum = dayPrice * 4 * overnights * (overnights > 7 ? 0.75 : 1);
  58.  
  59.    console.log(`Annie\'s holiday in the ${destination} sea costs ${totalSum.toFixed(2)} lv.`);
  60.    return;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement