Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculatePrice(input) {
- const [month, hoursSpentStr, groupSizeStr, timeOfDay] = input;
- const hoursSpent = Number(hoursSpentStr);
- const groupSize = Number(groupSizeStr);
- let pricePerHour;
- switch (month) {
- case "march":
- case "april":
- case "may":
- if (timeOfDay === "day") {
- pricePerHour = 10.50;
- } else {
- pricePerHour = 8.40;
- }
- break;
- case "june":
- case "july":
- case "august":
- if (timeOfDay === "day") {
- pricePerHour = 12.60;
- } else {
- pricePerHour = 10.20;
- }
- break;
- default:
- console.log("Invalid month");
- return;
- }
- if (groupSize >= 4) {
- pricePerHour *= 0.9;
- }
- if (hoursSpent >= 5) {
- pricePerHour *= 0.5;
- }
- const totalCost = pricePerHour * hoursSpent * groupSize;
- const pricePerPersonPerHour = pricePerHour;
- console.log(`Price per person for one hour: ${pricePerPersonPerHour.toFixed(2)}`);
- console.log(`Total cost of the visit: ${totalCost.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement