Advertisement
-Enigmos-

examPreparation(Eli).js

Nov 11th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function exam(input) {
  2.     let index = 0;
  3.     let badGradesAllowed = Number(input[index]);
  4.     index++;
  5.     let command = input[index];
  6.     index++;
  7.  
  8.     let badGrades = 0;
  9.     let sumGrades = 0;
  10.     let taskCounter = 0;
  11.     let examPass = true;
  12.  
  13.     while (command !== "Enough") {
  14.         let currentGrade = Number(input[index]);
  15.         index++;
  16.         taskCounter++;
  17.         sumGrades += currentGrade;
  18.  
  19.         if (currentGrade <= 4) {
  20.             badGrades++;
  21.         }
  22.         if (badGrades === badGradesAllowed) {
  23.             examPass = false;
  24.             console.log(`You need a break, ${badGrades} poor grades.`);
  25.             break;
  26.         }
  27.  
  28.         command = input[index];
  29.         index++;
  30.     }
  31.     let average = sumGrades / taskCounter;
  32.     let lastTask = input[index - 3];
  33.  
  34.     if (examPass) {
  35.         console.log(`Average score: ${average.toFixed(2)}`);
  36.         console.log(`Number of problems: ${(taskCounter)}`);
  37.         console.log(`Last problem: ${lastTask}`);
  38.     }
  39. }
  40.  
  41. exam(["3", "Money", "6", "Story", "4", "Spring Time", "5", "Bus", "6", "Enough"]);
  42. exam(["2", "Income", "3", "Game Info", "6", "Best Player", "4"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement