TZinovieva

Basketball Tournament

Dec 22nd, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function basketballTournament(input) {
  2.     let index = 0;
  3.     let name = input[index];
  4.     index++;
  5.    
  6.    
  7.     let allGamesCounter = 0;
  8.     let wonGame = 0;
  9.     let lostGame = 0;
  10.     while (name !== "End of tournaments") {
  11.         let matchesNumber = Number(input[index]);
  12.         index++;
  13.  
  14.         let gamesCounter = 0;
  15.         for (let i = 1; i <= matchesNumber; i++) {
  16.             let hostPoints = Number(input[index]);
  17.             index++;
  18.             let guestPoints = Number(input[index]);
  19.             index++;
  20.             gamesCounter++;
  21.  
  22.             if (hostPoints > guestPoints) {
  23.                 wonGame++;
  24.                 console.log(`Game ${gamesCounter} of tournament ${name}: win with ${hostPoints - guestPoints} points.`);
  25.             } else {
  26.                 lostGame++;
  27.                 console.log(`Game ${gamesCounter} of tournament ${name}: lost with ${guestPoints - hostPoints} points.`);
  28.             }
  29.         }
  30.         allGamesCounter += gamesCounter;
  31.  
  32.         name = input[index];
  33.         index++;
  34.         }
  35.    
  36.     if (name === "End of tournaments") {
  37.         console.log(`${(wonGame * 100 / allGamesCounter).toFixed(2)}% matches win`);
  38.         console.log(`${(lostGame * 100 / allGamesCounter).toFixed(2)}% matches lost`);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment