Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fishingBoat(input) {
- let groupBudget = Number(input.shift());
- let season = input.shift();
- let fishersCount = Number(input.shift());
- let discount = 0;
- let currentprice = 0;
- let rent;
- switch (season) {
- case "Spring":
- rent = 3000;
- if (fishersCount <= 6) {
- discount = 0.1;
- currentprice = rent - (rent * discount);
- } else if (fishersCount <= 11) {
- discount = 0.15;
- currentprice = rent - (rent * discount);
- } else if (fishersCount > 11) {
- discount = 0.25;
- currentprice = rent - (rent * discount);
- }
- if (fishersCount % 2 == 0) {
- currentprice = currentprice - (currentprice * 0.05);
- }
- if (groupBudget >= currentprice) {
- console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
- };
- break;
- case "Summer":
- rent = 4200;
- if (fishersCount <= 6) {
- discount = 0.1;
- currentprice = rent - (rent * discount);
- } else if (fishersCount <= 11) {
- discount = 0.15;
- currentprice = rent - (rent * discount);
- } else if (fishersCount > 11) {
- discount = 0.25;
- currentprice = rent - (rent * discount);
- }
- if (fishersCount % 2 == 0) {
- currentprice = currentprice - (currentprice * 0.05);
- }
- if (groupBudget >= currentprice) {
- console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
- };
- break;
- case "Autumn":
- rent = 4200;
- if (fishersCount <= 6) {
- discount = 0.1;
- currentprice = rent - (rent * discount);
- } else if (fishersCount <= 11) {
- discount = 0.15;
- currentprice = rent - (rent * discount);
- } else if (fishersCount > 11) {
- discount = 0.25;
- currentprice = rent - (rent * discount);
- }
- if (groupBudget >= currentprice) {
- console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
- };
- break;
- case "Winter":
- rent = 2600;
- if (fishersCount <= 6) {
- discount = 0.1;
- currentprice = rent - (rent * discount);
- } else if (fishersCount <= 11) {
- discount = 0.15;
- currentprice = rent - (rent * discount);
- } else if (fishersCount > 11) {
- discount = 0.25;
- currentprice = rent - (rent * discount);
- }
- if (fishersCount % 2 == 0) {
- currentprice = currentprice - (currentprice * 0.05);
- }
- if (groupBudget >= currentprice) {
- console.log(`Yes! You have ${(groupBudget - currentprice).toFixed(2)} leva left.`);
- } else {
- console.log(`Not enough money! You need ${(currentprice - groupBudget).toFixed(2)} leva.`);
- };
- break;
- }
- }
- fishingBoat([3600, "Autumn", 6]);
Advertisement
Add Comment
Please, Sign In to add comment