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