Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function BestPlayer(input){
- let playerName = "";
- let prevName = "";
- let goals = 0;
- for (let i = 0; i < input.length; i++) {
- let currentData = input[i];
- if(i % 2 == 0){
- prevName = currentData;
- }
- if (i %2 == 1 && currentData > goals){
- goals = currentData;
- playerName = prevName;
- }
- }
- console.log(`${playerName} is the best player!`);
- if(goals >=3){
- console.log(`He has scored ${goals} goals and made a hat-trick !!!`);
- }else{
- console.log(`He has scored ${goals} goals.`)
- }
- }
- BestPlayer(["Silva",
- 5,
- "Harry Kane",
- 10]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement