Advertisement
ErolKZ

Untitled

Jul 14th, 2021
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function solve(input) {
  2.  
  3.  
  4. let lowGradesLimit = Number(input[0]);
  5.  
  6. let counter = 0;
  7.  
  8. let avgScore = 0;
  9.  
  10. let index = 1;
  11.  
  12. let counter2 = 0;
  13.  
  14. let nameOfTask = '';
  15.  
  16.  
  17. while (input[index] !== 'Enough') {
  18.  
  19.  
  20. let current = Number(input[index]);
  21.  
  22.  
  23. if (!isNaN(current)) {
  24.  
  25. avgScore += current;
  26.  
  27. counter2 += 1;
  28.  
  29.  
  30. if (current <= 4) {
  31.  
  32. counter += 1;
  33.  
  34. if (lowGradesLimit <= counter) {
  35.  
  36. console.log(`You need a break, ${counter} poor grades.`);
  37.  
  38. break;
  39. }
  40.  
  41.  
  42. }
  43.  
  44. } else {
  45.  
  46. nameOfTask = input[index];
  47.  
  48. }
  49.  
  50. index++;
  51.  
  52. }
  53.  
  54.  
  55. avgScore = avgScore / counter2;
  56.  
  57.  
  58. if (counter < lowGradesLimit) {
  59.  
  60. console.log(`Average score: ${avgScore.toFixed(2)}`);
  61. console.log(`Number of problems: ${counter2}`);
  62. console.log(`Last problem: ${nameOfTask}`);
  63.  
  64. }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement