Guest User

Untitled

a guest
Dec 7th, 2019
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function exam(input) {
  2. let numGrade= +input.shift();
  3. let countBadgrade = 0;
  4. let counter = 0;
  5. let allGrade = 0;
  6.  
  7. while (countBadgrade < numGrade) {
  8. let name = input.shift();
  9. let currGrade = +input.shift();
  10. let lastGrade = allGrade / counter
  11. allGrade += currGrade;
  12. if (currGrade <= 4) {
  13. countBadgrade++;
  14. }
  15.  
  16.  
  17. if (name == "Enough") {
  18.  
  19. console.log(`Average score: ${Math.abs(lastGrade.toFixed(2))}\nNumber of problems: ${counter}\nLast problem: ${name}`)
  20. break;
  21. }
  22. counter++;
  23. }
  24. if (countBadgrade >= numGrade) {
  25. console.log(`You need a break, ${countBadgrade} poor grades.`)
  26. }
  27.  
  28.  
  29. }
RAW Paste Data