Advertisement
Spocoman

08. Tennis Ranklist

Dec 24th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tennisRanklist(input) {
  2.     let tournamentsNumbers = parseInt(input[0]);
  3.     let points = parseInt(input[1]);
  4.     let tournamentPoints = 0;
  5.     let win = 0;
  6.  
  7.     for (let i = 2; i < tournamentsNumbers + 2; i++) {
  8.         let currentTournament = input[i];
  9.  
  10.         if (currentTournament === "W") {
  11.             tournamentPoints += 2000;
  12.             win++;
  13.         } else if (currentTournament === "F") {
  14.             tournamentPoints += 1200;
  15.         } else if (currentTournament === "SF") {
  16.             tournamentPoints += 720;
  17.         }
  18.     }
  19.  
  20.     console.log(`Final points: ${points + tournamentPoints}`);
  21.     console.log(`Average points: ${Math.floor(tournamentPoints / tournamentsNumbers)}`);
  22.     console.log(`${(100.0 * win / tournamentsNumbers).toFixed(2)}%`);
  23.  
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement