Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function graduation(input) {
- let index = 0;
- let name = input[index];
- index++;
- let yearCounter = 1;
- let allGrades = 0;
- let badGradesCounter = 0;
- let outOfSchool = false;
- while (yearCounter <= 12) {
- let annualGrade = Number(input[index]);
- index++;
- if (annualGrade < 4) {
- badGradesCounter++;
- if (badGradesCounter > 1) {
- outOfSchool = true;
- break;
- }
- continue;
- }
- allGrades += annualGrade;
- yearCounter++;
- }
- let averageGrade = allGrades / 12;
- if (outOfSchool) {
- console.log(`${name} has been excluded at ${yearCounter} grade`);
- } else {
- console.log(`${name} graduated. Average grade: ${averageGrade.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment