Liliana797979

задача 2 от упражненията While цикъл

Nov 10th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. function solve(input) {
  2. let index = 0;
  3. let maxUnsatisfyingGrades = Number(input[index++]);
  4. let unsatisfyingGrades = 0;
  5. let gradesSum = 0;
  6. let problemsCount = 0;
  7. let lastProblem = undefined;
  8.  
  9. let currentProblem = input[index++];
  10. while(currentProblem !== "Enough") {
  11. let currentGrade = Number(input[index++]);
  12.  
  13. if (currentGrade <= 4) {
  14. unsatisfyingGrades++;
  15.  
  16. if(unsatisfyingGrades === maxUnsatisfyingGrades) {
  17. break;
  18. }
  19. }
  20.  
  21. gradesSum += currentGrade;
  22. problemsCount++;
  23. lastProblem = currentProblem;
  24.  
  25. if(unsatisfyingGrades === maxUnsatisfyingGrades) {
  26. console.log(`You need a break, ${maxUnsatisfyingGrades} poor grades.`);
  27. } else {
  28. console.log(`Average score: ${(gradesSum / problemsCount).toFixed(2)}`);
  29. console.log(`Numbers of problems: ${problemsCount}`);
  30. console.log(`Last problem: ${lastProblem}`);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment