Hi,
I’m working on the “Build a Gradebook App” JavaScript challenge. I completed the studentMsg
function with correct logic and formatting, but the test still fails.
Expected string:
“Class average: 71.7. Your grade: F. You failed the course.”
My function returns exactly that. I used .toFixed(1)
and string concatenation as instructed. I also removed console.log and extra newlines.
Here’s my full code:
function getAverage(scores) {
let sum = 0;
for (const score of scores) {
sum += score;
}
return sum / scores.length;
}
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(score) {
return getGrade(score) !== "F";
}
function studentMsg(totalScores, studentScore) {
const average = getAverage(totalScores).toFixed(1);
const grade = getGrade(studentScore);
if (hasPassingGrade(studentScore)) {
return "Class average: " + average + ". Your grade: " + grade + ". You passed the course.";
} else {
return "Class average: " + average + ". Your grade: " + grade + ". You failed the course.";
}
}