gskorchev

exam preparation

Feb 8th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function examPreparation(input) {
  2.     const badGradesWatchCount = Number(input.shift());
  3.     let badGradeCount = 0;
  4.     let gradeCount = 0;
  5.     let scoreSum = 0;
  6.     let lastProblem = '';
  7.     let hasMetBadGradeCriteria = false;
  8.     while (input.length) {
  9.         const problemName = input.shift()
  10.         if (problemName === 'Enough') {
  11.             finished = true;
  12.             break;
  13.         }
  14.         const problemGrade = Number(input.shift())
  15.         if (problemGrade <= 4) {++badGradeCount }
  16.         if (badGradeCount === badGradesWatchCount) {
  17.             console.log(`You need a break, ${badGradesWatchCount} poor grades.`)
  18.             hasMetBadGradeCriteria = true;
  19.             break;
  20.         }
  21.         lastProblem = problemName;
  22.         scoreSum += problemGrade;
  23.         gradeCount++;
  24.     }
  25.     if (!hasMetBadGradeCriteria) {
  26.         const averageScore = (scoreSum / gradeCount).toFixed(2)
  27.         console.log(`Average score: ${averageScore}`);
  28.         console.log(`Number of problems: ${gradeCount}`);
  29.         console.log(`Last problem: ${lastProblem}`);
  30.     }
  31. }
  32.  
  33. examPreparation([3, "Money", 6, "Story", 4, "Spring time", 5, "Bus", 6, "Enough"]);
Advertisement
Add Comment
Please, Sign In to add comment