Liliana797979

viarno reshenie football tournament

Feb 26th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function footballTournement(input) {
  2.     let index = 0;
  3.     let teamName = input[index];
  4.     index++;
  5.     let playedMathesCount = Number(input[index]);
  6.     index++;
  7.     let points = 0;
  8.     let wins = 0;
  9.     let draws = 0;
  10.     let loses = 0;
  11.  
  12.  
  13.     for (let i = 1; i <= playedMathesCount; i++) {
  14.         let result = input[index];
  15.         index++;
  16.        
  17.         switch (result) {
  18.             case "W":
  19.                 wins++;
  20.                 points += 3;
  21.                 break;
  22.             case "D":
  23.                 draws++;
  24.                 points += 1;
  25.                 break;
  26.             case "L":
  27.                 loses++;
  28.                 break;
  29.         }
  30.     }
  31.      if (playedMathesCount === 0) {
  32.         console.log(`${teamName} hasn't played any games during this season.`);
  33.    } else {
  34.        let percentWin = (wins / playedMathesCount * 100).toFixed(2);
  35.        console.log(`${teamName} has won ${points} points during this season.`);
  36.        console.log(`Total stats:`);
  37.        console.log(`## W: ${wins}`);
  38.        console.log(`## D: ${draws}`);
  39.        console.log(`## L: ${loses}`);
  40.        console.log(`Win rate: ${percentWin}%`);
  41.    }
  42. }
  43.  
  44. footballTournement(["Liverpool", "10", "W", "D", "D", "W", "L", "W", "D", "D", "W", "W"]);
Advertisement
Add Comment
Please, Sign In to add comment