Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let students = Number(input[index]);
- index++;
- let topStudents = 0;
- let goodStudents = 0;
- let avarageStudents = 0;
- let failedStudents = 0;
- let avarageScore = 0;
- for (i = 1; i < input.length; i++) {
- if (+input[index] < 3.00) {
- failedStudents++;
- index++;
- } else if (+input[index] < 4.00) {
- avarageStudents++;
- index++;
- } else if (+input[index] < 5.00) {
- goodStudents++;
- index++;
- } else if (+input[index] >= 5.00) {
- topStudents++;
- index++;
- }
- }
- let sum = 0;
- for (i = 1; i < input.length; i++) {
- sum += +input[i];
- }
- avarageScore = sum / students;
- let topStudentsPercent = (topStudents / students) * 100;
- let goodStudentsPercent = (goodStudents / students) * 100;
- let avarageStudentsPercent = (avarageStudents / students) * 100;
- let failedStudentsPercent = (failedStudents / students) * 100;
- console.log(`Top students: ${topStudentsPercent.toFixed(2)}%`);
- console.log(`Between 4.00 and 4.99: ${goodStudentsPercent.toFixed(2)}%`);
- console.log(`Between 3.00 and 3.99: ${avarageStudentsPercent.toFixed(2)}%`);
- console.log(`Fail: ${failedStudentsPercent.toFixed(2)}%`);
- console.log(`Average: ${avarageScore.toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment