Liliana797979

viarno reshenie tennis ranklist

Feb 25th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function tennisRanklist(input) {
  3.     let tournamentsNumber = Number(input.shift());
  4.     let allPoints = Number(input.shift());
  5.     let currentPoints = 0;
  6.     let points = 0;
  7.     let winnerCounter = 0;
  8.     let stageInTournament = input.shift();
  9.  
  10.     for (let i = 1; i <= tournamentsNumber; i++) {  
  11.         if (stageInTournament == 'W') {
  12.             points = 2000;
  13.             winnerCounter++;
  14.         } else if (stageInTournament == 'F') {
  15.             points = 1200;
  16.         } else if (stageInTournament == 'SF') {
  17.             points = 720;
  18.         }
  19.         allPoints += points;
  20.         currentPoints += points;
  21.         stageInTournament = input.shift();
  22.     }
  23.     let averagePoints = currentPoints / tournamentsNumber;
  24.     let winnerPercent = winnerCounter / tournamentsNumber * 100;
  25.     console.log(`Final points: ${allPoints}`);
  26.     console.log(`Average points: ${Math.floor(averagePoints)}`);
  27.     console.log(`${winnerPercent.toFixed(2)}%`);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment