Advertisement
Marin171

Fishing Boat

Sep 7th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. function solve(input) {
  2. let budget = Number(input[0]);
  3. let season = input[1];
  4. let fishCount = Number(input[2]);
  5. let price = 0;
  6.  
  7. switch(season) {
  8. case "Spring":
  9. price = 3000;
  10. if(fishCount <= 6) {
  11. price *= 0.90;
  12. } else if(fishCount >= 7 && fishCount <= 11) {
  13. price *= 0.85;
  14. } else if(fishCount >= 12) {
  15. price *= 0.75;
  16. }
  17. break;
  18. case "Summer":
  19. price = 4200;
  20. if(fishCount <= 6) {
  21. price *= 0.90;
  22. } else if (fishCount >= 7 && fishCount <= 11) {
  23. price *= 0.85;
  24. } else if (fishCount >= 12) {
  25. price *= 0.75;
  26. }
  27. break;
  28. case "Autumn":
  29. price = 4200;
  30. if(fishCount <= 6) {
  31. price *= 0.90;
  32. } else if(fishCount >= 7 && fishCount <= 11) {
  33. price *= 0.85;
  34. } else if(fishCount >= 12) {
  35. price *= 0.75;
  36. }
  37. break;
  38. case "Winter":
  39. price = 2600;
  40. if(fishCount <= 6) {
  41. price *= 0.90;
  42. } else if(fishCount >= 7 && fishCount <= 11) {
  43. price &= 0.85;
  44. } else if(fishCount >= 12) {
  45. price *= 0.75;
  46. }
  47. break;
  48. }
  49. if(fishCount % 2 == 0 && season !== "Autumn") {
  50. price = price * 0.95;
  51. }
  52. let diff = Math.abs(budget - price);
  53. if(budget >= price) {
  54. console.log(`Yes! You have ${diff.toFixed(2)} leva left.`);
  55.  
  56. } else {
  57. console.log(`Not enough money! You need ${diff.toFixed(2)} leva.`);
  58. }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement