Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function footballTournament(input) {
- let index = 0;
- let footballClub = input[index];
- index++;
- let gamesPlayed = Number(input[index]);
- index++;
- let winCounter = 0;
- let drawCounter = 0;
- let loseCounter = 0;
- if (gamesPlayed === 0) {
- console.log(`${footballClub} hasn't played any games during this season.`);
- } else if (gamesPlayed > 0) {
- for (let i = 0; i < gamesPlayed; i++) {
- let currentGame = input[index];
- index++;
- if (currentGame === "W") {
- winCounter++;
- } else if (currentGame === "D") {
- drawCounter++;
- } else if (currentGame === "L") {
- loseCounter++;
- }
- }
- let points = (winCounter * 3) + drawCounter;
- let winRate = (winCounter / gamesPlayed) * 100;
- console.log(`${footballClub} has won ${points} points during this season.`);
- console.log(`Total stats:`);
- console.log(`## W: ${winCounter}`);
- console.log(`## D: ${drawCounter}`);
- console.log(`## L: ${loseCounter}`);
- console.log(`Win rate: ${winRate.toFixed(2)}%`);
- }
- }
- footballTournament(["Liverpool", "10", "W", "D", "D", "W", "L", "W", "D", "D", "W", "W"]);
- footballTournament(["Barcelona", "7", "W", "D", "L", "L", "W", "W", "D"]);
- footballTournament(["Chelsea", "0"]);
Advertisement
Add Comment
Please, Sign In to add comment