Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

  1. Your StudentMsg function should return the correct message based on the student’s score and the class average.

Your code so far

function getAverage(scores) {
    let sum = scores.reduce((acc, score) => acc + score, 0);
    return sum / scores.length;
}

function getGrade(score) {
    if (score === 100) return "A+";
    if (score >= 90) return "A";
    if (score >= 80) return "B";
    if (score >= 70) return "C";
    if (score >= 60) return "D";
    return "F";
}

function hasPassingGrade(score) {
    return getGrade(score) !== "F";
}

function studentMsg(totalScores, studentScore) {
    let avg = getAverage(totalScores).toFixed(1);
    let grade = getGrade(studentScore);
    let status = hasPassingGrade(studentScore) ? "You passed the course." : "You failed the course.";
    
    return `Class average: ${avg}. Your grade: ${grade}. ${status}`;
}

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build a Gradebook App - Build a Gradebook App

You don’t need to use the toFixed method here:

That’s what is causing the code to fail.

Thanks!! I almost didn’t finish it

1 Like