Advertisement
Spocoman

Football Tournament

Feb 24th, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function footballTournament(input) {
  2.     let team = input.shift();
  3.     let matches = Number(input.shift());
  4.     let w = 0;
  5.     let d = 0;
  6.     let l = 0;
  7.     let counter = 0;
  8.  
  9.     for (let i = 0; i < matches && matches > 0; i++) {
  10.         let result = input.shift();
  11.         switch (result) {
  12.             case "W":
  13.                 w++;
  14.                 break;
  15.             case "D":
  16.                 d++;
  17.                 break;
  18.             case "L":
  19.                 l++;
  20.                 break;
  21.         }
  22.     }
  23.  
  24.     if (matches === 0) {
  25.         console.log(`${team} hasn't played any games during this season.`);
  26.    } else {
  27.        console.log(`${team} has won ${w * 3 + d} points during this season.`);
  28.        console.log("Total stats:");
  29.        console.log(`## W: ${w}`);
  30.        console.log(`## D: ${d}`);
  31.        console.log(`## L: ${l}`);
  32.        console.log(`Win rate: ${(w / matches * 100).toFixed(2)}%`);
  33.    }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement