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 allGrades = 0;
- let badGrade = 0;
- let yearCounter = 1;
- let isExcluded = false;
- while (yearCounter <= 12) {
- let annualGrade = Number(input[index]);
- index++;
- if (annualGrade < 4) {
- badGrade++;
- if (badGrade > 1) {
- isExcluded = true;
- console.log(`${name} has been excluded at ${yearCounter} grade`);
- break;
- }
- continue;
- }
- allGrades += annualGrade;
- yearCounter++;
- }
- if (!isExcluded) {
- let averageGrade = allGrades / 12;
- console.log(`${name} graduated. Average grade: ${(averageGrade).toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment