TZinovieva

Football Results JS

Dec 6th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function footballResults(input) {
  2.     let wonMatches = 0;
  3.     let lostMatches = 0
  4.     let drawnMatches = 0;
  5.  
  6.     let hostResult = 0;
  7.     let guestResult = 0;
  8.     for (let i = 0; i <= 2; i++) {
  9.         let match = input[i];
  10.  
  11.             hostResult = match.charAt(0);
  12.             guestResult = match.charAt(2);
  13.            
  14.                 if (hostResult > guestResult) {
  15.                     wonMatches++;
  16.                 } else if (hostResult < guestResult) {
  17.                     lostMatches++;
  18.                 } else if (hostResult === guestResult) {
  19.                     drawnMatches++;
  20.                 }
  21.  
  22.     }
  23.     console.log(`Team won ${wonMatches} games.`);
  24.     console.log(`Team lost ${lostMatches} games.`);
  25.     console.log(`Drawn games: ${drawnMatches}`);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment