tedo1111

Untitled

Oct 15th, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2. function whileLoop(input) {
  3. let index = 0;
  4. let name = input[index];
  5. index++;
  6.  
  7. let maxGoals = 0;
  8. let hatTrick = false;
  9. let currName = '';
  10.  
  11. while (name !== 'END') {
  12. if (index >= input.length) {
  13. break;
  14. }
  15.  
  16. let goals = +input[index];
  17. index++;
  18.  
  19. if (goals >= maxGoals) {
  20. maxGoals = goals;
  21. currName = name;
  22. }
  23.  
  24.  
  25.  
  26. if (goals >= 3) {
  27. hatTrick = true;
  28. }
  29.  
  30. if (index < input.length) {
  31. name = input[index];
  32. index++;
  33. }
  34. }
  35.  
  36. if (hatTrick) {
  37. console.log(`${currName} is the best player!`);
  38. console.log(`He has scored ${maxGoals} goals and made a hat-trick !!!`);
  39. } else {
  40. console.log(`${currName} is the best player!`);
  41. console.log(`He has scored ${maxGoals} goals.`);
  42. }
  43. }
  44.  
  45. whileLoop(["Rooney", "1", "Junior", "2", "Paolinio", "2", "END"]);
  46.  
Advertisement
Add Comment
Please, Sign In to add comment