Advertisement
-Enigmos-

hotelRoom(noDiscount).js

Oct 6th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hotelRoom(input) {
  2.     let index = 0;
  3.     let month = input[index];
  4.     index++;
  5.     let nights = Number(input[index]);
  6.     index++;
  7.     let May, October = [65, 50];
  8.     let June, September = [68.70, 75.20];
  9.     let July, August = [77, 76];
  10.     let discountApartment = 0;
  11.     let discountStudio = 0;
  12.  
  13.     if (month === "May" || month === "October") {
  14.         let apartmentPrice = May || October[0] * nights;
  15.         let studioPrice = May || October[1] * nights;
  16.         if (nights >= 14) {
  17.             discountApartment += 0.1;
  18.             discountStudio += 0.3;
  19.         } else if (nights >= 7) {
  20.             discountStudio += 0.05;
  21.         }
  22.         apartmentPrice -= (apartmentPrice * discountApartment);
  23.         studioPrice -= (studioPrice * discountStudio);
  24.  
  25.         console.log(`Apartment: ${apartmentPrice.toFixed(2)} lv.`);
  26.         console.log(`Studio: ${studioPrice.toFixed(2)} lv.`);
  27.  
  28.     } else if (month === "June" || month === "September") {
  29.         let apartmentPrice = June || September[0] * nights;
  30.         let studioPrice = June || September[1] * nights;
  31.  
  32.         apartmentPrice -= (apartmentPrice * discountApartment);
  33.         studioPrice -= (studioPrice * discountStudio);
  34.        
  35.         console.log(`Apartment: ${apartmentPrice.toFixed(2)} lv.`);
  36.         console.log(`Studio: ${studioPrice.toFixed(2)} lv.`);
  37.  
  38.     } else if (month === "July" || month === "August") {
  39.         let apartmentPrice = July || August[0] * nights;
  40.         let studioPrice = July || August[1] * nights;
  41.  
  42.         if (nights >= 14) {
  43.             discountApartment += 0.1;
  44.         }
  45.         apartmentPrice -= (apartmentPrice * discountApartment);
  46.         studioPrice -= (studioPrice * discountStudio);
  47.  
  48.         console.log(`Apartment: ${apartmentPrice.toFixed(2)} lv.`);
  49.         console.log(`Studio: ${studioPrice.toFixed(2)} lv.`);
  50.     }
  51. }
  52.  
  53. hotelRoom(["June", "14"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement