Advertisement
PowerCell46

Tennis Ranklist JS

Oct 1st, 2022
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tennisRanklist(input) {
  2. let index = 0
  3. let numberOfTourneys = Number(input[index]);
  4. index++;
  5. let startingPoints = Number(input[index]);
  6. index++;
  7. let wonPoints = 0;
  8. let wonCounter = 0;
  9.  
  10. for(let rotatingTourneys = 0; rotatingTourneys < numberOfTourneys; rotatingTourneys++) {
  11. let currentTourneyResult = input[index];
  12. index++;
  13.  
  14. if(currentTourneyResult === "W") {
  15. wonPoints+=2000;
  16. wonCounter+=1;
  17. } else if(currentTourneyResult === "F") {
  18. wonPoints+=1200;
  19. } else if(currentTourneyResult === "SF") {
  20. wonPoints+=720;
  21. }
  22. }
  23.  
  24. let finalPoints = startingPoints + wonPoints;
  25. console.log("Final points: " + finalPoints);
  26.  
  27. let averagePoints = (wonPoints/numberOfTourneys);
  28. console.log("Average points: " + Math.floor(averagePoints));
  29.  
  30. let percentageOfWinnigs = (wonCounter/ numberOfTourneys) * 100;
  31. console.log(percentageOfWinnigs.toFixed(2) + "%");
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement