Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function asd(input) {
- let badGradeLimit = Number(input[0]);
- let index = 1;
- let taskName = input[index];
- let taskGrade = Number(input[index + 1]);
- let badGradesCounter = 0;
- let avvCounter = 0;
- let gradeSum = 0;
- let lastProblem = "";
- while (taskName !== "Enough") {
- lastProblem = taskName;
- avvCounter++;
- gradeSum += taskGrade;
- if (taskGrade <= 4) {
- badGradesCounter++;
- }
- if (badGradesCounter === badGradeLimit) {
- console.log(`You need a break, ${badGradesCounter} poor grades.`);
- break;
- }
- index += 2;
- taskName = input[index];
- taskGrade = Number(input[index + 1]);
- }
- if (taskName === "Enough") {
- console.log(`Average score: ${(gradeSum / avvCounter).toFixed(2)}`);
- console.log(`Number of problems: ${avvCounter}`);
- console.log(`Last problem: ${lastProblem}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement