Tell us what’s happening:
I’ve completed all exercises except for seventeen and twenty two most of them meet the requirements but not returning the grade as “F” for example seventeen. And twenty two does not meet the correct message based on the student score or class averages.
Your code so far
function getAverage(scores) {
// Sum the scores and compute the average, rounded to one decimal place.
const total = scores.reduce((acc, score) => acc + score, 0);
return parseFloat((total / scores.length).toFixed(1));
}
function getGrade(score) {
if (score === 100) {
return "A+";
} else if (score >= 90) {
return "A";
} else if (score >= 80) {
return "B";
} else if (score >= 70) {
return "C";
} else if (score >= 60) {
return "D";
} else {
return "F";
}
}
function hasPassingGrade(grade) {
// Return false if the grade is "F", true otherwise.
return grade !== "F";
}
function studentMsg(scores, studentScore) {
// Compute the class average and determine the student's grade.
const average = getAverage(scores);
const grade = getGrade(studentScore);
const result = hasPassingGrade(grade) ? "passed" : "failed";
return `Class average: ${average}. Your grade: ${grade}. You ${result} the course.`;
}
// For demonstration, here are the test cases:
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
// Expected output: 71.7
console.log(getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]));
// Expected output: 85.4
console.log(getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100]));
// Expected output: 92.4
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
// Expected output: "Class average: 71.7. Your grade: F. You failed the course."
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
// Expected output: "Class average: 50.8. Your grade: A+. You passed the course."
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0
Challenge Information:
Build a Gradebook App - Build a Gradebook App