Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function grades(input) {
- let student = Number(input[0]);
- let grade3 = 0;
- let grade4 = 0;
- let grade5 = 0;
- let grade6 = 0;
- let gradeSum = 0;
- for (let i = 1; i <= student; i++) {
- let grade = Number(input[i]);
- if (grade >= 5) {
- grade6++;
- } else if (grade >= 4) {
- grade5++;
- } else if (grade >= 3) {
- grade4++;
- } else if (grade >= 2) {
- grade3++;
- }
- gradeSum += grade;
- }
- console.log(`Top students: ${(grade6 / student * 100).toFixed(2)}%`);
- console.log(`Between 4.00 and 4.99: ${(grade5 / student * 100).toFixed(2)}%`);
- console.log(`Between 3.00 and 3.99: ${(grade4 / student * 100).toFixed(2)}%`);
- console.log(`Fail: ${(grade3 / student * 100).toFixed(2)}%`);
- console.log(`Average: ${(gradeSum / student).toFixed(2)}`);
- }
- РЕШЕНИЕ С WHILE И SHIFT():
- function grades(input) {
- let student = Number(input.shift());
- let grade3 = 0;
- let grade4 = 0;
- let grade5 = 0;
- let grade6 = 0;
- let gradeSum = 0;
- while (input.length !== 0) {
- let grade = Number(input.shift());
- if (grade >= 5) {
- grade6++;
- } else if (grade >= 4) {
- grade5++;
- } else if (grade >= 3) {
- grade4++;
- } else if (grade >= 2) {
- grade3++;
- }
- gradeSum += grade;
- }
- console.log(`Top students: ${(grade6 / student * 100).toFixed(2)}%`);
- console.log(`Between 4.00 and 4.99: ${(grade5 / student * 100).toFixed(2)}%`);
- console.log(`Between 3.00 and 3.99: ${(grade4 / student * 100).toFixed(2)}%`);
- console.log(`Fail: ${(grade3 / student * 100).toFixed(2)}%`);
- console.log(`Average: ${(gradeSum / student).toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement