Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fishingBoat(arg1, arg2, arg3) {
- // Read input data
- let groupBudget = Number(arg1);
- let season = arg2;
- let fishersCount = Number(arg3);
- // Determine the price for renting the boat depending on the season
- let boatRent = 0;
- switch (season) {
- case 'Spring':
- boatRent = 3000;
- break;
- case 'Summer':
- case 'Autumn':
- boatRent = 4200;
- break;
- case 'Winter':
- boatRent = 2600;
- break;
- }
- // Add a discount to the rent price depending on the number of people in the group
- if (fishersCount <= 6) {
- boatRent *= 0.90;
- } else if (fishersCount >= 7 && fishersCount <= 11) {
- boatRent *= 0.85;
- } else if (fishersCount >= 12) {
- boatRent *= 0.75;
- }
- // Add an additional discount for an even number of people and a season other than autumn
- if (fishersCount % 2 === 0) {
- if (season !== 'Autumn') {
- boatRent *= 0.95;
- }
- }
- // Calculate money difference
- let moneyDifference = groupBudget - boatRent;
- // Print output
- if (moneyDifference >= 0) {
- console.log(`Yes! You have ${moneyDifference.toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${Math.abs(moneyDifference).toFixed(2)} leva.`);
- }
- }
- // Test with sample input data
- fishingBoat(3000, 'Summer', 11);
- fishingBoat(3600, 'Autumn', 6);
- fishingBoat(2000, 'Winter', 13);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement