Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function examPreparation(input) {
- const badGradesWatchCount = Number(input.shift());
- let badGradeCount = 0;
- let gradeCount = 0;
- let scoreSum = 0;
- let lastProblem = '';
- let hasMetBadGradeCriteria = false;
- while (input.length) {
- const problemName = input.shift()
- if (problemName === 'Enough') {
- finished = true;
- break;
- }
- const problemGrade = Number(input.shift())
- if (problemGrade <= 4) {++badGradeCount }
- if (badGradeCount === badGradesWatchCount) {
- console.log(`You need a break, ${badGradesWatchCount} poor grades.`)
- hasMetBadGradeCriteria = true;
- break;
- }
- lastProblem = problemName;
- scoreSum += problemGrade;
- gradeCount++;
- }
- if (!hasMetBadGradeCriteria) {
- const averageScore = (scoreSum / gradeCount).toFixed(2)
- console.log(`Average score: ${averageScore}`);
- console.log(`Number of problems: ${gradeCount}`);
- console.log(`Last problem: ${lastProblem}`);
- }
- }
- examPreparation([3, "Money", 6, "Story", 4, "Spring time", 5, "Bus", 6, "Enough"]);
Advertisement
Add Comment
Please, Sign In to add comment