Liliana797979

football tournement

Feb 26th, 2021
131
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.     let points = 0;
  12.  
  13.     if (playedMathesCount === 0) {
  14.         console.log(`${teamName} hasn't played any games during this season.`);
  15.    } else {
  16.        wins = 0;
  17.        draws = 0;
  18.        loses = 0;
  19.        points = 0;
  20.    }
  21.    for (let i = 1; i < playedMathesCount; i++) {
  22.        let result = input[index];
  23.        index++;
  24.        
  25.        switch (result) {
  26.            case "W":
  27.                wins++;
  28.                points += 3;
  29.                break;
  30.            case "D":
  31.                draws++;
  32.                points += 1;
  33.                break;
  34.            case "L":
  35.                loses++;
  36.                break;
  37.        }
  38.    }
  39.    let percentWin = (wins / playedMathesCount * 100).toFixed(2);
  40.    console.log(`${teamName} has won {брой спечелени точки} points during this season`);
  41.    console.log(`Total stats:`);
  42.    console.log(`## W: ${wins}`);
  43.    console.log(`## D: ${draws}`);
  44.    console.log(`## L: ${loses}`);
  45.    console.log(`Win rate: ${percentWin}%`);
  46. }
  47.  
  48. footballTournement(["Liverpool", "10", "W", "D", "D", "W", "L", "W", "D", "D", "W"]);
Advertisement
Add Comment
Please, Sign In to add comment