Tell us what’s happening:
- Your studentMsg function should return the correct message based on the student’s score and the class average. still wrong
Your code so far
function getAverage(scores) {
let total = 0;
for (let i = 0; i < scores.length; i++) {
total += scores[i];
}
return total / 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) {
const grade = getGrade(score);
return grade !== "F";
}
function studentMsg(scores, studentScore) {
const avg = getAverage(scores);
const avgFixed = Number(avg.toFixed(1)); // ensures correct number formatting
const grade = getGrade(studentScore);
const passed = hasPassingGrade(studentScore);
const result = passed ? "You passed the course." : "You failed the course.";
return "Class average: " + avgFixed.toFixed(1) + ". Your grade: " + grade + ". " + result;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Challenge Information:
Build a Gradebook App - Build a Gradebook App