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 studentMsg(totalScores, studentScore) {
// Calculate the class average using the getAverage function
let average = getAverage(totalScores);
// Determine the student's grade using the getGrade function
let grade = getGrade(studentScore);
// Determine if the student passed or failed
let passed = grade !== "F";
// Construct the message based on pass or fail status
if (passed) {
return `Class average: ${average.toFixed(2)}. Your grade: ${grade}. You passed the course.`;
} else {
return `Class average: ${average.toFixed(2)}. Your grade: ${grade}. You failed the course.`;
}
}
// Example usage:
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
I removed it and it presented another error that it didn’t have before
if (passed) {
return `Class average: ${average}. Your grade: ${grade}. You passed the course.`;
} else {
return `Class average: ${average}. Your grade: ${grade}. You failed the course.`;
}
I used template literals and passed the test. at first i thought i failed because of it. I checked the instructions again and changed the console.log to return statement and kept the template literals and passed it.