Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exam(input) {
- let index = 0;
- let badGradesAllowed = Number(input[index]);
- index++;
- let command = input[index];
- index++;
- let badGrades = 0;
- let sumGrades = 0;
- let taskCounter = 0;
- let examPass = true;
- while (command !== "Enough") {
- let currentGrade = Number(input[index]);
- index++;
- taskCounter++;
- sumGrades += currentGrade;
- if (currentGrade <= 4) {
- badGrades++;
- }
- if (badGrades === badGradesAllowed) {
- examPass = false;
- console.log(`You need a break, ${badGrades} poor grades.`);
- break;
- }
- command = input[index];
- index++;
- }
- let average = sumGrades / taskCounter;
- let lastTask = input[index - 3];
- if (examPass) {
- console.log(`Average score: ${average.toFixed(2)}`);
- console.log(`Number of problems: ${(taskCounter)}`);
- console.log(`Last problem: ${lastTask}`);
- }
- }
- exam(["3", "Money", "6", "Story", "4", "Spring Time", "5", "Bus", "6", "Enough"]);
- exam(["2", "Income", "3", "Game Info", "6", "Best Player", "4"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement