Tell us what’s happening:
i dont know what is wrong , can someone give me a hint?
no matter the score, it always returns:
“You failed the course.”
Why is the ternary operator not working as expected here?
How should I fix this?
Your code so far
function getAverage(scores){
const total = scores.reduce((acc, score) => score + acc,0 )
return total / scores.length;
}
function getGrade(score) {
switch (true) {
case score === 100:
return "A+";
case score >= 90:
return "A";
case score >= 80:
return "B";
case score >= 70:
return "C";
case score >= 60:
return "D";
case score < 60:
return "F";
default:
return "Invalid score";
}
}
function hasPassingGrade(score){
return getGrade(score) !== "F";
}
function studentMsg(scores, score){
let av = getAverage(scores);
let grade = getGrade(score);
let pass = hasPassingGrade(score)
return `Class average: ${av}. Your grade: ${grade}.` + pass == true ? "You passed the course." : "You failed the course."
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Challenge Information:
Build a Gradebook App - Build a Gradebook App