Advertisement
ggeorgiev88

footballCompetition

Dec 13th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function footballCompetition(input) {
  2.     let name = input[0];
  3.     let numberPlayedMatches = Number(input[1]);
  4.     let index = 2;
  5.     let currentMatch = input[index];
  6.     let winCounter = 0
  7.     let egalCounter = 0
  8.     let louseCounter = 0
  9.     let winPoints = 0
  10.     let mathesCouter = 0
  11.  
  12.     for (let x = 1; x <= numberPlayedMatches; x++) {
  13.         mathesCouter++
  14.         switch (currentMatch) {
  15.             case "W":
  16.                 winPoints += 3;
  17.                 winCounter++; break;
  18.             case "D":
  19.                 winPoints += 1
  20.                 egalCounter++; break;
  21.             case "L":
  22.                 louseCounter++; break
  23.         }
  24.         index++;
  25.         currentMatch = input[index];
  26.     }
  27.     if (numberPlayedMatches === 0) {
  28.         console.log(`${name} hasn't played any games during this season.`);
  29.        return;
  30.    } else {
  31.        let winRate = (winCounter / mathesCouter) * 100;
  32.        console.log(`${name} has won ${winPoints} points during this season.`);
  33.        console.log("Total stats:");
  34.        console.log(`## W: ${winCounter}`);
  35.        console.log(`## D: ${egalCounter}`);
  36.        console.log(`## L: ${louseCounter}`);
  37.        console.log(`Win rate: ${winRate.toFixed(2)}%`);
  38.  
  39.  
  40.    }
  41.  
  42.  
  43.  
  44. }
  45.  
  46. // footballCompetition(["Liverpool"
  47. //     , "10"
  48. //     , "W"
  49. //     , "D"
  50. //     , "D"
  51. //     , "W"
  52. //     , "L"
  53. //     , "W"
  54. //     , "D"
  55. //     , "D"
  56. //     , "W"
  57. //     , "W"]);
  58.  
  59. footballCompetition(["Chelsea",
  60.    "0"
  61.    ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement