Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function BestPlayer(input){
  2.     let playerName = "";
  3.     let prevName = "";
  4.     let goals = 0;
  5.  
  6.     for (let i = 0; i < input.length; i++) {
  7.         let currentData = input[i];
  8.  
  9.         if(i % 2 == 0){
  10.             prevName = currentData;
  11.        
  12.         }
  13.         if (i %2 == 1 && currentData > goals){
  14.             goals = currentData;
  15.             playerName = prevName;
  16.         }
  17.     }
  18.     console.log(`${playerName} is the best player!`);
  19.     if(goals >=3){
  20.     console.log(`He has scored ${goals} goals and made a hat-trick !!!`);
  21.     }else{
  22.         console.log(`He has scored ${goals} goals.`)
  23.     }
  24. }
  25. BestPlayer(["Silva",
  26.     5,
  27.     "Harry Kane",
  28.     10]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement