desislava_topuzakova

Untitled

Nov 4th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function solve(input) {
  2. let index = 0;
  3. let students = Number(input[index]);
  4. index++;
  5. let topStudents = 0;
  6. let goodStudents = 0;
  7. let avarageStudents = 0;
  8. let failedStudents = 0;
  9. let avarageScore = 0;
  10.  
  11. for (i = 1; i < input.length; i++) {
  12. if (+input[index] < 3.00) {
  13. failedStudents++;
  14. index++;
  15. } else if (+input[index] < 4.00) {
  16. avarageStudents++;
  17. index++;
  18. } else if (+input[index] < 5.00) {
  19. goodStudents++;
  20. index++;
  21. } else if (+input[index] >= 5.00) {
  22. topStudents++;
  23. index++;
  24. }
  25. }
  26. let sum = 0;
  27.  
  28. for (i = 1; i < input.length; i++) {
  29. sum += +input[i];
  30. }
  31.  
  32. avarageScore = sum / students;
  33.  
  34.  
  35. let topStudentsPercent = (topStudents / students) * 100;
  36. let goodStudentsPercent = (goodStudents / students) * 100;
  37. let avarageStudentsPercent = (avarageStudents / students) * 100;
  38. let failedStudentsPercent = (failedStudents / students) * 100;
  39.  
  40.  
  41. console.log(`Top students: ${topStudentsPercent.toFixed(2)}%`);
  42. console.log(`Between 4.00 and 4.99: ${goodStudentsPercent.toFixed(2)}%`);
  43. console.log(`Between 3.00 and 3.99: ${avarageStudentsPercent.toFixed(2)}%`);
  44. console.log(`Fail: ${failedStudentsPercent.toFixed(2)}%`);
  45. console.log(`Average: ${avarageScore.toFixed(2)}`);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment