Advertisement
zarkoto223

examPreparationWhileExersicesSoftUni

Mar 12th, 2024
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function asd(input) {
  2.   let badGradeLimit = Number(input[0]);
  3.   let index = 1;
  4.   let taskName = input[index];
  5.   let taskGrade = Number(input[index + 1]);
  6.   let badGradesCounter = 0;
  7.   let avvCounter = 0;
  8.   let gradeSum = 0;
  9.   let lastProblem = "";
  10.  
  11.   while (taskName !== "Enough") {
  12.     lastProblem = taskName;
  13.     avvCounter++;
  14.     gradeSum += taskGrade;
  15.     if (taskGrade <= 4) {
  16.       badGradesCounter++;
  17.     }
  18.     if (badGradesCounter === badGradeLimit) {
  19.       console.log(`You need a break, ${badGradesCounter} poor grades.`);
  20.       break;
  21.     }
  22.     index += 2;
  23.     taskName = input[index];
  24.     taskGrade = Number(input[index + 1]);
  25.   }
  26.   if (taskName === "Enough") {
  27.     console.log(`Average score: ${(gradeSum / avvCounter).toFixed(2)}`);
  28.     console.log(`Number of problems: ${avvCounter}`);
  29.     console.log(`Last problem: ${lastProblem}`);
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement