Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function whileLoop(input) {
- let index = 0;
- let name = input[index];
- index++;
- let maxGoals = 0;
- let hatTrick = false;
- let currName = '';
- while (name !== 'END') {
- if (index >= input.length) {
- break;
- }
- let goals = +input[index];
- index++;
- if (goals >= maxGoals) {
- maxGoals = goals;
- currName = name;
- }
- if (goals >= 3) {
- hatTrick = true;
- }
- if (index < input.length) {
- name = input[index];
- index++;
- }
- }
- if (hatTrick) {
- console.log(`${currName} is the best player!`);
- console.log(`He has scored ${maxGoals} goals and made a hat-trick !!!`);
- } else {
- console.log(`${currName} is the best player!`);
- console.log(`He has scored ${maxGoals} goals.`);
- }
- }
- whileLoop(["Rooney", "1", "Junior", "2", "Paolinio", "2", "END"]);
Advertisement
Add Comment
Please, Sign In to add comment