Guest User

PB - Graduation pt.2

a guest
May 21st, 2020
56
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 count = 1;
  7.     let totalGrade = 0;
  8.     let excluded = 0;
  9.     let isExcluded = false;
  10.  
  11.     while(count <=12) {
  12.         let grade = Number(input[index]);
  13.         index++;
  14.         if(grade >= 4.00) {
  15.             count++;
  16.             totalGrade += grade;
  17.         } else if(grade < 4.00){
  18.             excluded++;
  19.         }
  20.         if(excluded = 2) {
  21.           isExcluded = true;
  22.         }
  23.         if(isExcluded = true) {
  24.           console.log(`${name} has been excluded at ${count} grade`);
  25.           return;
  26.         }                  
  27.     }
  28.     let averageGrade = totalGrade /12;
  29.     console.log(`${name} graduated. Average grade: ${averageGrade.toFixed(2)}`);
  30. }
RAW Paste Data