Advertisement
mbratanov

04. Fishing Boat

Feb 17th, 2025 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fishingBoat(arg1, arg2, arg3) {
  2.  
  3.     // Read input data
  4.     let groupBudget = Number(arg1);
  5.     let season = arg2;
  6.     let fishersCount = Number(arg3);
  7.  
  8.     // Determine the price for renting the boat depending on the season
  9.     let boatRent = 0;
  10.  
  11.     switch (season) {
  12.         case 'Spring':
  13.             boatRent = 3000;
  14.             break;
  15.         case 'Summer':
  16.         case 'Autumn':
  17.             boatRent = 4200;
  18.             break;
  19.         case 'Winter':
  20.             boatRent = 2600;
  21.             break;
  22.     }
  23.  
  24.     // Add a discount to the rent price depending on the number of people in the group
  25.     if (fishersCount <= 6) {
  26.         boatRent *= 0.90;
  27.     } else if (fishersCount >= 7 && fishersCount <= 11) {
  28.         boatRent *= 0.85;
  29.     } else if (fishersCount >= 12) {
  30.         boatRent *= 0.75;
  31.     }
  32.  
  33.     // Add an additional discount for an even number of people and a season other than autumn
  34.     if (fishersCount % 2 === 0) {
  35.         if (season !== 'Autumn') {
  36.             boatRent *= 0.95;
  37.         }
  38.     }
  39.  
  40.     // Calculate money difference
  41.     let moneyDifference = groupBudget - boatRent;
  42.  
  43.     // Print output
  44.     if (moneyDifference >= 0) {
  45.         console.log(`Yes! You have ${moneyDifference.toFixed(2)} leva left.`);
  46.     } else {
  47.         console.log(`Not enough money! You need ${Math.abs(moneyDifference).toFixed(2)} leva.`);
  48.     }
  49. }
  50.  
  51. // Test with sample input data
  52. fishingBoat(3000, 'Summer', 11);
  53. fishingBoat(3600, 'Autumn', 6);
  54. fishingBoat(2000, 'Winter', 13);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement