desito07

Cruise Games

May 1st, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. function cruiseGames(input) {
  2. let name = input.shift();
  3. let gamesCount = Number(input.shift());
  4.  
  5. let volleyball = 0;
  6. let counterV = 0;
  7. let tennis = 0;
  8. let counterT = 0;
  9. let badminton = 0;
  10. let counterB = 0;
  11. let sum = 0;
  12. let sum1 = 0;
  13.  
  14. for (let i = 0; i < gamesCount; i++) {
  15. let gameName = input.shift();
  16. let gamesPoints = Number(input.shift());
  17.  
  18. if (gameName === "volleyball") {
  19. volleyball += gamesPoints + gamesPoints * 0.07;
  20. counterV++;
  21. } else if (gameName === "tennis") {
  22. tennis += gamesPoints + gamesPoints * 0.05;
  23. counterT++;
  24. } else if (gameName === "badminton") {
  25. badminton += gamesPoints + gamesPoints * 0.02;
  26. counterB++;
  27. }
  28. }
  29. let avrVolleyball = Math.floor(volleyball / counterV);
  30. let avrTennis = Math.floor(tennis / counterT);
  31. let avrBadminton = Math.floor(badminton / counterB);
  32.  
  33. if (avrVolleyball >= 75 && avrTennis >= 75 && avrBadminton >= 75) {
  34. sum = volleyball + tennis + badminton;
  35. console.log(
  36. `Congratulations, ${name}! You won the cruise games with ${Math.floor(
  37. sum
  38. )} points.`
  39. );
  40. } else {
  41. sum1 = volleyball + tennis + badminton;
  42. console.log(
  43. `Sorry, ${name}, you lost. Your points are only ${Math.floor(sum1)}.`
  44. );
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment