Advertisement
RRusev77

Random exercise

Mar 29th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(overnights, type, rating) {
  2.     overnights = Number(overnights) - 1;
  3.  
  4.     const accomodationTypes = {
  5.         'room for one person': {
  6.             price: 18,
  7.             discount: [0,0,0]
  8.         },
  9.         'apartment': {
  10.             price: 25,
  11.             discount: [0.3, 0.35, 0.5]
  12.         },
  13.         'president apartment': {
  14.             price: 35,
  15.             discount: [0.1, 0.15, 0.2]
  16.         }
  17.     };
  18.  
  19.     let finalPrice;
  20.  
  21.     if (overnights < 10) {
  22.         finalPrice = accomodationTypes[type].price * overnights;
  23.         finalPrice -= finalPrice * accomodationTypes[type].discount[0];
  24.     } else if (overnights >= 10 && overnights <= 15) {
  25.         finalPrice = accomodationTypes[type].price * overnights;
  26.         finalPrice -= finalPrice * accomodationTypes[type].discount[1];
  27.     } else if (overnights > 15) {
  28.         finalPrice = accomodationTypes[type].price * overnights;
  29.         finalPrice -= finalPrice * accomodationTypes[type].discount[2];
  30.     }
  31.  
  32.     if(rating == 'positive') {
  33.         finalPrice *= 1.25;
  34.     } else if (rating == 'negative') {
  35.         finalPrice *= 0.9;
  36.     }
  37.  
  38.     console.log(finalPrice.toFixed(2));
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement