Advertisement
Spocoman

08. Graduation

Dec 27th, 2021 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function graduation(input) {
  2.     let name = input[0];
  3.     let gradeNum = 0;
  4.     let index = 1;
  5.     let fail = 0;
  6.     let sum = 0;
  7.  
  8.     while (gradeNum !== 12) {
  9.         let score = Number(input[index++]);
  10.         if (score < 4) {
  11.             fail++;
  12.             if (fail === 2) {
  13.                 break;
  14.             }
  15.         } else {
  16.             sum += score;
  17.         }
  18.         gradeNum++;
  19.     }
  20.  
  21.     if (fail === 2) {
  22.         console.log(`${name} has been excluded at ${gradeNum} grade`);
  23.     } else {
  24.         console.log(`${name} graduated. Average grade: ${((sum / 12)).toFixed(2)}`);
  25.     }
  26. }
  27.  
  28. РEШЕНИЕ СЪС SHIFT И ТЕРНАРЕН ОПЕРАТОР:
  29.  
  30. function Graduation(input) {
  31.     let name = input.shift();
  32.     let gradeNum = 0;
  33.     let fail = 0;
  34.     let sum = 0;
  35.  
  36.     while (input.length !== 0){
  37.         let score = Number(input.shift());
  38.         score < 4? fail++ : sum += score;
  39.         if (fail === 2) {
  40.             break;
  41.         }
  42.         gradeNum++;
  43.     }
  44.     console.log(fail === 2? `${name} has been excluded at ${gradeNum} grade`
  45.                 : `${name} graduated. Average grade: ${((sum / 12)).toFixed(2)}`);
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement