Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tennisRanklist(input) {
  2.     let tournamentsNumber = Number(input.shift());
  3.     let startPointsNumberInRanklist = Number(input.shift());
  4.     let points = 0;
  5.     let allPoints = 0;
  6.     let winnerCounter = 0;
  7.     let stageInTournament = input.shift();
  8.  
  9.     for (let i = 1; i <= tournamentsNumber; i++) {
  10.         let startingPoints = startPointsNumberInRanklist;    
  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 += startPointsNumberInRanklist + points;
  20.         stageInTournament = input.shift();
  21.        
  22.        
  23.     }
  24.     let averagePoints = allPoints / tournamentsNumber;
  25.     let winnerPercent = winnerCounter / tournamentsNumber * 100;
  26.     console.log(`Final points: ${allPoints}`);
  27.     console.log(`Average points: ${averagePoints}`);
  28.     console.log(`${winnerPercent.toFixed(2)}%`);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement