Tell us what’s happening:
My code cannot pass the test case 17 and 22. I don’t know if the code has some error.
Your code so far
function getAverage(arrayOfTestScore) {
let sum = 0;
for (let each of arrayOfTestScore) {
sum += each;
}
let average = sum / arrayOfTestScore.length;
return Number(average.toFixed(1));
}
function getGrade(studentScore) {
if (studentScore === 100) return "A+";
if (studentScore >= 90) return "A";
if (studentScore >= 80) return "B";
if (studentScore >= 70) return "C";
if (studentScore >= 60) return "D";
return "F";
}
function hasPassingGrade(grade) {
return grade !== "F";
}
function studentMsg(arrayOfScore, score) {
const averageScore = getAverage(arrayOfScore).toFixed(1); // convert to string with 1 decimal
const grade = getGrade(score);
const passed = hasPassingGrade(grade);
if (passed) {
return `Class average: ${averageScore}. Your grade: ${grade}. You passed the course.`;
} else {
return `Class average: ${averageScore}. Your grade: ${grade}. You failed the course.`;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Challenge Information:
Build a Gradebook App - Build a Gradebook App