function bestPlayer(input) { let bestPlayerName = ""; let bestPlayerGoals = 0; let bestPlayerHetric = false; let inputLength = input.length let i = 0; while (true) { if (i > inputLength) { break; } let currrentEle = input[i]; let nextEle = input[i + 1] if (currrentEle === "END") { break; } if (bestPlayerGoals < nextEle) { bestPlayerName = currrentEle; bestPlayerGoals = nextEle; if (bestPlayerGoals >= 3) { bestPlayerHetric = true; } if (bestPlayerGoals >= 10) { break; } } i = i + 2; } // console.log(`${bestPlayerName} : ${bestPlayerGoals}`); console.log(`${bestPlayerName} is the best player!`); if (bestPlayerHetric) { console.log(`He has scored ${bestPlayerGoals} goals and made a hat-trick !!!`); } else { console.log(`He has scored ${bestPlayerGoals} goals.`); } } bestPlayer(["Neymar", "2", "Ronaldo", "1", "Messi", "3", "END"]);