Advertisement
Spocoman

Best Player

Jan 4th, 2022 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bestPlayer(input) {
  2.     let bestPlayer = "";
  3.     let bestScore = 0;
  4.  
  5.     for(let i = 0; i < input.length && bestScore < 10; i++){
  6.         let player = input[i++];
  7.         let goals = Number(input[i]);
  8.         if (goals > bestScore) {
  9.             bestPlayer = player;
  10.             bestScore = goals;
  11.         }
  12.     }
  13.  
  14.     console.log(`${bestPlayer} is the best player!`);
  15.     if (bestScore < 3) {
  16.         console.log(`He has scored ${bestScore} goals.`);
  17.     } else {
  18.         console.log(`He has scored ${bestScore} goals and made a hat-trick !!!`);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement