PowerCell46

baking competition JS

Oct 14th, 2022
1,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterCompetition(input) {
  2. let index = 0;
  3. let numberOfKozunaks = Number(input[index]);
  4. let kozunakCounter = 0;
  5. index++;
  6.  
  7. let baker = "";
  8. let grade = 0;
  9. let finalGrade = 0;
  10. let maxGrade = 0;
  11. let bestBaker = "";
  12.  
  13. while(kozunakCounter < numberOfKozunaks) {
  14. baker = input[index];
  15. index++;
  16. grade = input[index];
  17.  
  18. while(grade !== "Stop") {
  19. grade = Number(input[index]);
  20.     finalGrade += grade;
  21.     index++;
  22.     grade = input[index];
  23. }
  24.  
  25. console.log(baker + " has " + finalGrade + " points.");
  26. if(finalGrade > maxGrade) {
  27.     maxGrade = finalGrade;
  28.     bestBaker = baker;
  29.     console.log(baker + " is the new number 1!");
  30. }
  31.  
  32. finalGrade = 0;
  33. index++;
  34. kozunakCounter++;
  35. }
  36.  
  37. console.log(bestBaker + " won competition with " + maxGrade + " points!");
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment