Advertisement
bebo231312312321

Untitled

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