Advertisement
bebo231312312321

Untitled

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