TZinovieva

Graduation 100/100

Oct 12th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function graduation(input) {
  2.     let index = 0;
  3.     let name = input[index];
  4.     index++;
  5.  
  6.     let yearCounter = 1;
  7.     let allGrades = 0;
  8.     let badGradesCounter = 0;
  9.     let outOfSchool = false;
  10.  
  11.     while (yearCounter <= 12) {
  12.         let annualGrade = Number(input[index]);
  13.         index++;
  14.        
  15.         if (annualGrade < 4) {
  16.             badGradesCounter++;
  17.  
  18.             if (badGradesCounter > 1) {
  19.                 outOfSchool = true;
  20.                 break;
  21.             }
  22.             continue;
  23.         }
  24.         allGrades += annualGrade;
  25.         yearCounter++;
  26.     }
  27.         let averageGrade = allGrades / 12;
  28.         if (outOfSchool) {
  29.             console.log(`${name} has been excluded at ${yearCounter} grade`);
  30.         } else {
  31.             console.log(`${name} graduated. Average grade: ${averageGrade.toFixed(2)}`);
  32.         }        
  33. }
Advertisement
Add Comment
Please, Sign In to add comment