Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculateNeededMoney(days, typeOfRoom, rating) {
- let invDays = Number(days);
- let invTypeOfRoom = typeOfRoom.toLowerCase();
- let nights = invDays - 1;
- let apartmentPrice = 25;
- let presidentPrice = 35;
- let roomOnePerson = 18;
- let totalPrice = 0;
- if (invTypeOfRoom === 'apartment') {
- totalPrice = nights * apartmentPrice;
- if (nights < 10) {
- totalPrice = totalPrice * 0.7;
- } else if (nights >= 10 && nights <= 15) {
- totalPrice = totalPrice * 0.65;
- } else {
- totalPrice = totalPrice * 0.5;
- }
- } else if (invTypeOfRoom === 'president apartment') {
- totalPrice = nights * presidentPrice;
- if (nights < 10) {
- totalPrice = totalPrice * 0.9;
- } else if (nights >= 10 && nights <= 15) {
- totalPrice = totalPrice * 0.85;
- } else {
- totalPrice = totalPrice * 0.8;
- }
- } else if (invTypeOfRoom === 'room for one person') {
- totalPrice = nights * roomOnePerson;
- }
- if (rating === 'positive') {
- let tip = totalPrice * 0.25;
- totalPrice = totalPrice + tip;
- } else {
- let discount = totalPrice * 0.1;
- totalPrice = totalPrice - discount;
- }
- console.log(totalPrice.toFixed(2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement