Java Script Fundametals : task 4 Exercise - 04. Vacation
4. Vacation
You are given a group of people, type of the group, and day of the week they are going to stay. Based on that information calculate how much they have to pay and print that price on the console. Use the table below. In each cell is the price for a single person. The output should look like that:
"Total price: {price}". The price should be formatted to the second decimal point.
|
Friday |
Saturday |
Sunday |
Students |
8.45 |
9.80 |
10.46 |
Business |
10.90 |
15.60 |
16 |
Regular |
15 |
20 |
22.50 |
There are also discounts based on some conditions:
- Students – if the group is bigger than or equal to 30 people you should reduce the total price by 15%
- Business – if the group is bigger than or equal to 100 people 10 of them can stay for free.
- Regular – if the group is bigger than or equal 10 and less than or equal to 20 reduce the total price by 5%
You should reduce the prices in that EXACT order
Моето решение е, (дава ми само 83т в judge??) Някъде бъркам? :
function vacation(groupPeople, typeGroup, dayWeek) {
let totalSum = 0;
if (dayWeek === "Friday" ){
if( typeGroup=== "Students"){
totalSum = groupPeople * 8.45;
} else if (typeGroup === "Business"){
totalSum = groupPeople * 10.90;
} else if (typeGroup === "Regular"){
totalSum = groupPeople* 15;
}
} else if (dayWeek === "Saturday"){
if ( typeGroup === "Students"){
totalSum= groupPeople * 9.80;
} else if (typeGroup === "Business"){
totalSum = groupPeople* 15.60;
} else if (typeGroup=== "Regular"){
totalSum = groupPeople* 20;
}
} else if (dayWeek === "Sunday"){
if ( typeGroup === "Students"){
totalSum= groupPeople* 10.46;
} else if (typeGroup === "Business"){
totalSum= groupPeople * 16;
} else if (typeGroup=== "Regular"){
totalSum= groupPeople * 22.50;
}
if ( groupPeople >= 30 && typeGroup === "Students"){
totalSum = totalSum - (0.15*totalSum);
} else if (groupPeople >= 100 && typeGroup === "Business" ){
totalSum = totalSum - ((totalSum /groupPeople) * 10 );
} else if(typeGroup === "Regular" && groupPeople>=10 && groupPeople<=20) {
totalSum = totalSum*0.95;
}
}
console.log(`Total price: ${totalSum.toFixed(2)}`);
}
vacation(30,
"Students",
"Sunday"
)