-
Notifications
You must be signed in to change notification settings - Fork 0
/
skiTrip.js
56 lines (47 loc) · 1.12 KB
/
skiTrip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function skiVacation(input) {
let days = Number(input[0]);
let roomType = input[1];
let rating = input[2];
let pricePerNight = 0;
switch (roomType) {
case "room for one person":
pricePerNight = 18;
break;
case "apartment":
pricePerNight = 25;
break;
case "president apartment":
pricePerNight = 35;
break;
}
let totalNights = days - 1;
let totalCost = pricePerNight * totalNights;
let discount = 0;
if (totalNights > 15) {
switch (roomType) {
case "apartment":
discount = 0.5;
break;
case "president apartment":
discount = 0.2;
break;
}
} else if (totalNights >= 10 && totalNights <= 15) {
switch (roomType) {
case "apartment":
discount = 0.35;
break;
case "president apartment":
discount = 0.15;
break;
}
}
let finalPrice = totalCost - totalCost * discount;
if (rating === "positive") {
finalPrice += finalPrice * 0.25;
} else {
finalPrice -= finalPrice * 0.1;
}
console.log(finalPrice.toFixed(2));
}
skiVacation(["14", "apartment", "positive"]);