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":
- pricePerHour = timeOfDay === "day" ? 10.50 : 8.40;
- break;
- case "june": case "july": case "august":
- pricePerHour = timeOfDay === "day" ? 12.60 : 10.20;
- break;
- default:
- console.log("Invalid month");
- return;
- }
- if (groupSize >= 4) pricePerHour *= 0.9;
- if (hoursSpent >= 5) pricePerHour *= 0.5;
- console.log(`Price per person for one hour: ${pricePerHour.toFixed(2)}`);
- console.log(`Total cost of the visit: ${(pricePerHour * hoursSpent * groupSize).toFixed(2)}`);
- }
- calculatePrice(["july", "5", "5", "night"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement