Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function footballTournement(input) {
- let index = 0;
- let teamName = input[index];
- index++;
- let playedMathesCount = Number(input[index]);
- index++;
- let points = 0;
- let wins = 0;
- let draws = 0;
- let loses = 0;
- for (let i = 1; i <= playedMathesCount; i++) {
- let result = input[index];
- index++;
- switch (result) {
- case "W":
- wins++;
- points += 3;
- break;
- case "D":
- draws++;
- points += 1;
- break;
- case "L":
- loses++;
- break;
- }
- }
- if (playedMathesCount === 0) {
- console.log(`${teamName} hasn't played any games during this season.`);
- } else {
- let percentWin = (wins / playedMathesCount * 100).toFixed(2);
- console.log(`${teamName} has won ${points} points during this season.`);
- console.log(`Total stats:`);
- console.log(`## W: ${wins}`);
- console.log(`## D: ${draws}`);
- console.log(`## L: ${loses}`);
- console.log(`Win rate: ${percentWin}%`);
- }
- }
- footballTournement(["Liverpool", "10", "W", "D", "D", "W", "L", "W", "D", "D", "W", "W"]);
Advertisement
Add Comment
Please, Sign In to add comment