Advertisement
Didart

Tennis Ranklist

Apr 9th, 2022
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tennisRanklist(input) {
  2.  
  3.     let tournaments = Number(input[0]);
  4.     let startingPoints = Number(input[1]);
  5.     let points = startingPoints;
  6.     let wins = 0;
  7.  
  8.     for (let index = 2; index < input.length; index++) {
  9.         let stage = input[index];
  10.  
  11.         switch (stage) {
  12.             case 'W':
  13.                 points += 2000;
  14.                 wins++;
  15.                 break;
  16.             case 'F':
  17.                 points += 1200;
  18.                 break;
  19.             case 'SF':
  20.                 points += 720;
  21.                 break;
  22.         }
  23.     }
  24.     let avgPoints = (points - startingPoints) / tournaments;
  25.     let percentWins = (wins / tournaments) * 100;
  26.  
  27.     console.log(`Final points: ${points}`);
  28.     console.log(`Average points: ${Math.floor(avgPoints)}`);
  29.     console.log(`${percentWins.toFixed(2)}%`);
  30.  
  31. }
  32.  
  33. tennisRanklist(["5", "1400", "F", "SF", "W", "W", "SF"])
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement