TZinovieva

Tennis Ranklist 100/100

Oct 1st, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tennisRanklist(input) {
  2. let tournaments = Number(input[0]);
  3. let startPoints = Number(input[1]);
  4.  
  5. let wonTournaments = 0;
  6. let currentPoints = 0;
  7.  
  8. for (let i = 2; i <= tournaments + 1; i++) {
  9.     let stage = input[i];
  10.  
  11.     if (stage === "W") {
  12.         currentPoints += 2000;
  13.         wonTournaments++;
  14.     } else if (stage === "F") {
  15.         currentPoints += 1200;
  16.     } else if (stage === "SF") {
  17.         currentPoints += 720;
  18.     }
  19. }
  20. let totalPoints = startPoints + currentPoints;
  21. let percentWonTournaments = wonTournaments / tournaments * 100;
  22.  
  23. console.log(`Final points: ${totalPoints}`);
  24. console.log(`Average points: ${Math.floor(currentPoints / tournaments)}`);
  25. console.log(`${percentWonTournaments.toFixed(2)}%`);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment