Advertisement
Guest User

Ski Trip

a guest
Apr 4th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculateNeededMoney(days, typeOfRoom, rating) {
  2.     let invDays = Number(days);
  3.     let invTypeOfRoom = typeOfRoom.toLowerCase();
  4.     let nights = invDays - 1;
  5.     let apartmentPrice = 25;
  6.     let presidentPrice = 35;
  7.     let roomOnePerson = 18;
  8.     let totalPrice = 0;
  9.  
  10.     if (invTypeOfRoom === 'apartment') {
  11.         totalPrice = nights * apartmentPrice;
  12.         if (nights < 10) {
  13.             totalPrice = totalPrice * 0.7;
  14.         } else if (nights >= 10 && nights <= 15) {
  15.             totalPrice = totalPrice * 0.65;
  16.         } else {
  17.             totalPrice = totalPrice * 0.5;
  18.         }
  19.     } else if (invTypeOfRoom === 'president apartment') {
  20.         totalPrice = nights * presidentPrice;
  21.         if (nights < 10) {
  22.             totalPrice = totalPrice * 0.9;
  23.         } else if (nights >= 10 && nights <= 15) {
  24.             totalPrice = totalPrice * 0.85;
  25.         } else {
  26.             totalPrice = totalPrice * 0.8;
  27.         }
  28.     } else if (invTypeOfRoom === 'room for one person') {
  29.         totalPrice = nights * roomOnePerson;
  30.     }
  31.     if (rating === 'positive') {
  32.         let tip = totalPrice * 0.25;
  33.         totalPrice = totalPrice + tip;
  34.     } else {
  35.         let discount = totalPrice * 0.1;
  36.         totalPrice = totalPrice - discount;
  37.     }
  38.     console.log(totalPrice.toFixed(2));
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement