Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function footballCompetition(input) {
- let name = input[0];
- let numberPlayedMatches = Number(input[1]);
- let index = 2;
- let currentMatch = input[index];
- let winCounter = 0
- let egalCounter = 0
- let louseCounter = 0
- let winPoints = 0
- let mathesCouter = 0
- for (let x = 1; x <= numberPlayedMatches; x++) {
- mathesCouter++
- switch (currentMatch) {
- case "W":
- winPoints += 3;
- winCounter++; break;
- case "D":
- winPoints += 1
- egalCounter++; break;
- case "L":
- louseCounter++; break
- }
- index++;
- currentMatch = input[index];
- }
- if (numberPlayedMatches === 0) {
- console.log(`${name} hasn't played any games during this season.`);
- return;
- } else {
- let winRate = (winCounter / mathesCouter) * 100;
- console.log(`${name} has won ${winPoints} points during this season.`);
- console.log("Total stats:");
- console.log(`## W: ${winCounter}`);
- console.log(`## D: ${egalCounter}`);
- console.log(`## L: ${louseCounter}`);
- console.log(`Win rate: ${winRate.toFixed(2)}%`);
- }
- }
- // footballCompetition(["Liverpool"
- // , "10"
- // , "W"
- // , "D"
- // , "D"
- // , "W"
- // , "L"
- // , "W"
- // , "D"
- // , "D"
- // , "W"
- // , "W"]);
- footballCompetition(["Chelsea",
- "0"
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement