Advertisement
Liliana797979

Viarno reshenie exam preparation

Feb 11th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function examPreparation(input){
  3.     let index = 0;
  4.     let badGrades = Number(input[index]);
  5.     index++;
  6.     let taskName = input[index];
  7.     index++;
  8.     let grade = Number(input[index]);
  9.     let badGradesCounter = 0;
  10.     let total = 0;
  11.    
  12.     while(taskName !== "Enough"){
  13.         index++;
  14.         taskName = input[index];
  15.         if(grade<=4){
  16.             badGradesCounter++;
  17.             if(badGradesCounter===badGrades){
  18.                 console.log(`You need a break, ${badGradesCounter} poor grades.`);
  19.                 break;
  20.             }
  21.         }
  22.         total+=grade;
  23.         index++;
  24.         grade = Number(input[index]);
  25.        
  26.     }
  27.     if(taskName === "Enough"){
  28.         console.log(`Average score: ${(total/(Number(index-2)/2)).toFixed(2)}`);
  29.         console.log(`Number of problems: ${(index-2)/2}`);
  30.         console.log(`Last problem: ${input[index-3]}`);
  31.     }
  32.  
  33. }
  34. //examPreparation(["3","Money","6","Story","4","Spring Time","5","Bus","6","Enough"]);
  35. examPreparation(["2","Income","3","Game Info","6","Best Player","4"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement