Advertisement
ggeorgiev88

bestPlayer

Dec 13th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bestPlayer(input) {
  2.     let index = 0
  3.     let playerName = input[index];
  4.     index++;
  5.     let score = input[index];
  6.     let maxGoals = Number.MIN_SAFE_INTEGER
  7.     let bestPlayer = ""
  8.  
  9.     while (playerName !== "END") {
  10.         score = Number(input[index]);
  11.         if (score > maxGoals) {
  12.             maxGoals = score
  13.             if (playerName !== "END") {
  14.                 bestPlayer = playerName
  15.             } else {
  16.                 break;
  17.             }
  18.             if (score >= 10) {
  19.                 console.log(`${bestPlayer} is the best player`);
  20.                 console.log(`He has scored ${maxGoals} goals and made a hat-trick`);
  21.                 return;
  22.             }
  23.  
  24.         } else {
  25.             index++;
  26.             playerName = input[index];
  27.             index++;
  28.         }
  29.  
  30.  
  31.     }
  32.     if (maxGoals >= 3) {
  33.         console.log(`${bestPlayer} is the best player`);
  34.         console.log(`He has scored ${maxGoals} goals and made a hat-trick`);
  35.     } else if (maxGoals < 3) {
  36.         console.log(`He has scored ${maxGoals} goals `);
  37.     }
  38.  
  39.  
  40.  
  41. }
  42.  
  43. bestPlayer(["Neymar", "2", "Ronaldo", "1", "Messi", "3", "END"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement