Advertisement
Spocoman

Basketball Tournament

Jan 7th, 2022 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function basketballTournament(input) {
  2.     let tournament, games, team1, team2, win = 0, lost = 0;
  3.  
  4.     while ((tournament = input.shift()) !== "End of tournaments") {
  5.         games = Number(input.shift());
  6.         for (let game = 1; game <= games; game++) {
  7.             team1 = Number(input.shift());
  8.             team2 = Number(input.shift());
  9.             if (team1 > team2) {
  10.                 console.log(`Game ${game} of tournament ${tournament}: win with ${team1 - team2} points.`);
  11.                 win++;
  12.             } else {
  13.                 console.log(`Game ${game} of tournament ${tournament}: lost with ${team2 - team1} points.`);
  14.                 lost++;
  15.             }
  16.         }
  17.     }
  18.  
  19.     console.log(`${(win / (win + lost) * 100).toFixed(2)}% matches win`);
  20.     console.log(`${(lost / (win + lost) * 100).toFixed(2)}% matches lost`);
  21.     return;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement