Advertisement
bebo231312312321

Untitled

Feb 24th, 2024
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculatePrice(input) {
  2.     const [month, hoursSpentStr, groupSizeStr, timeOfDay] = input;
  3.     const hoursSpent = Number(hoursSpentStr);
  4.     const groupSize = Number(groupSizeStr);
  5.     let pricePerHour;
  6.  
  7.   switch (month) { case "march": case "april": case "may":
  8.         pricePerHour = timeOfDay === "day" ? 10.50 : 8.40;
  9.         break;
  10.     case "june": case "july": case "august":
  11.         pricePerHour = timeOfDay === "day" ? 12.60 : 10.20;
  12.         break;
  13.     default:
  14.         console.log("Invalid month");
  15.         return;
  16. }
  17.     if (groupSize >= 4) pricePerHour *= 0.9;
  18.      if (hoursSpent >= 5) pricePerHour *= 0.5;
  19.  
  20.     console.log(`Price per person for one hour: ${pricePerHour.toFixed(2)}`);
  21.     console.log(`Total cost of the visit: ${(pricePerHour * hoursSpent * groupSize).toFixed(2)}`);
  22. }
  23.  
  24.  
  25. calculatePrice(["july", "5", "5", "night"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement