Tell us what’s happening:
Why is it, that every time I get to the end of these thing, I get an error message? I am stuck on … I read it 500,000 times and it is correct.
22. 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) {
if(scores.length === 0) return 0;
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(scores, studentScore){
let average = parseFloat(getAverage(scores).toFixed(1));
let studentGrade = getGrade(studentScore);
let passMsg = hasPassingGrade(studentScore) ? "You passed the course." : "You failed the course.";
return `Class average: ${average}. Your grade: ${studentGrade}. ${passMsg}`;
}
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/136.0.0.0 Safari/537.36 Edg/136.0.0.0
Challenge Information:
Build a Gradebook App - Build a Gradebook App