Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calculatePrice(input) {
- let [month, hoursSpentStr, groupSizeStr, timeOfDay] = input;
- let hoursSpent = Number(hoursSpentStr);
- let 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;
- }
- let totalCost = pricePerHour * hoursSpent * groupSize;
- let 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