Advertisement
PowerCell46

Exam Preparation JS

Oct 4th, 2022
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function examPreparation(input) {
  2. let index = 0;
  3. let numberOfBadGrades = Number(input[index]);
  4. let badGradesCounter = 0;
  5. index++;
  6. let nameOfTheTask = input[index];
  7. index++;
  8. let gradeForTheTask = Number(input[index]);
  9. let sumOfGrades = 0;
  10. let numberOfTasks = 0;
  11. let enough = false;
  12. let failiure = false;
  13.  
  14. while(nameOfTheTask !== "Enough") {
  15. if(gradeForTheTask <= 4) {
  16. badGradesCounter++;
  17. if(badGradesCounter === numberOfBadGrades) {
  18. failiure = true;
  19.     break;
  20. }}
  21. sumOfGrades+= gradeForTheTask;
  22. numberOfTasks++;
  23. index++;
  24. nameOfTheTask = input[index];
  25. index++;
  26. gradeForTheTask = Number(input[index]);
  27. if(nameOfTheTask === "Enough") {
  28. enough = true;
  29. }
  30. }
  31.  
  32. let averageGrade = sumOfGrades / numberOfTasks;
  33. if(enough === true) {
  34. console.log("Average score: " + averageGrade.toFixed(2));
  35. console.log("Number of problems: " + numberOfTasks);
  36. console.log("Last problem: " + input[index - 3]);
  37. } else if(failiure === true) {
  38. console.log("You need a break, " + badGradesCounter + " poor grades.");
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement