Advertisement
drkskwlkr

Room Rate Calculation

Aug 15th, 2022 (edited)
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.48 KB | Source Code | 0 0
  1. function theMandalorian(input) {
  2.  
  3.   let period = input[0] ;
  4.   let nights = Number(input[1]) ;
  5.  
  6.   let priceStudio = 0 ;
  7.   let priceApartment = 0 ;
  8.   let discountStudio = 0 ;
  9.   let discountApartment = 0 ;
  10.  
  11.   // Determine total cost of stay per property type for every month
  12.   switch (period) {
  13.     case "May":
  14.     case "October":   priceStudio = nights * 50.00 ; priceApartment = nights * 65.00 ; break ;
  15.     case "June":
  16.     case "September": priceStudio = nights * 75.20 ; priceApartment = nights * 68.70 ; break ;
  17.     case "July":
  18.     case "August":    priceStudio = nights * 76.00 ; priceApartment = nights * 77.00 ; break ;
  19.   }
  20.  
  21.   // Determine discounts for Studio
  22.   if (period === "May" || period === "October") {
  23.     if (nights > 14) {
  24.       discountStudio = 30/100 ;
  25.     } else if (nights > 7) {
  26.       discountStudio = 5/100 ;
  27.     } else {
  28.       discountStudio = 0 ;
  29.     }
  30.   } else if (period === "June" || period === "September") {
  31.     if (nights > 14) {
  32.       discountStudio = 20/100 ;
  33.     } else {
  34.       discountStudio = 0 ;
  35.     }
  36.   }
  37.  
  38.   // Determine discounts for Apartment
  39.   if (nights > 14) {
  40.     discountApartment = 10/100 ;
  41.   } else {
  42.     discountApartment = 0 ;
  43.   }
  44.  
  45.   let priceStudioDiscounted = priceStudio * (1 - discountStudio) ;
  46.   let priceApartmentDiscounted = priceApartment * (1 - discountApartment) ;
  47.  
  48.   console.log(`Apartment: ${priceApartmentDiscounted.toFixed(2)} lv.`) ;
  49.   console.log(`Studio: ${priceStudioDiscounted.toFixed(2)} lv.`) ;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement