Tell us what’s happening:
my code works however i can’t the test won’t pass
Your code so far
let testScore = [92, 88, 12, 77, 57, 100, 67, 38, 97, 89]
function getAverage(testScore) {let sum = 0;
for (let average of testScore) {sum += average / testScore.length}
return sum;
}
let studentScore = getAverage(testScore);
function getGrade(studentScore) {
if (studentScore === 100) {return "A+"}
else if (studentScore >= 90) {return "A"}
else if (studentScore >= 80) {return "B"}
else if (studentScore >= 70) {return "C"}
else if (studentScore >= 60) {return "D"}
else {return "F"}
};
let studentGrade = getGrade(studentScore);
function hasPassingGrade(studentGrade) {
if (studentGrade == "F") {return false;}
else {return true;}
}
let passingGrade = hasPassingGrade(studentGrade);
function studentMsg(studentScore, studentGrade){if (passingGrade == true) {
return `Class average: ${studentScore}. Your grade: ${studentGrade}. You passed the course.
`}
else {return `Class average: ${studentScore}. Your grade: ${studentGrade}. You failed the course.
`}
}
console.log(studentMsg(studentScore, studentGrade))
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 Edg/135.0.0.0
Challenge Information:
Build a Gradebook App - Build a Gradebook App
ILM
April 22, 2025, 12:06pm
2
Don’t you see your output in the console?
Class average: 71.7. r grade: C. You passed the course.
This is missing a part of the requested message
Is this really the student’s score?
i can’t see it’s missing anything
yes it is, can you elaborate more
No. That is not the student score. It’s an average of all student scores you declared in the testScore
array, a variable name that does not represent what that array contains. The student score is what you pass to the studentMsg()
function when you do this:
studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)
i edited the code still doesn’t pass
let scores = new Array(10)
function getAverage(scores) {let sum = 0;
for (let average of scores) {sum += average / scores.length}
return sum;}
let classAverage = getAverage(scores);
let studentScore;
function getGrade(studentScore) {
if (studentScore === 100) {return "A+"}
else if (studentScore >= 90) {return "A"}
else if (studentScore >= 80) {return "B"}
else if (studentScore >= 70) {return "C"}
else if (studentScore >= 60) {return "D"}
else {return "F"}
};
let studentGrade = getGrade(studentScore);
function hasPassingGrade(studentGrade) {
if (studentGrade === "F") {return false;}
else {return true;}
}
let passingGrade = hasPassingGrade(studentGrade);
function studentMsg(classAverage, studentGrade){
if (passingGrade == true) {
return "Class average: " + classAverage + ". Your grade: " + studentGrade + ". You passed the course."}
else {return "Class average: " + classAverage + ". Your grade: " + studentGrade + ". You failed the course."}
}
console.log(studentMsg(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]), getGrade(37)));
console.log(studentMsg(getAverage([56, 23, 89, 42, 75, 11, 68, 34, 91, 19]), getGrade(100)));
You have declared several variables in the global space:
let scores = new Array(10)
let classAverage = getAverage(scores);
let studentScore;
let studentGrade = getGrade(studentScore);
let passingGrade = hasPassingGrade(studentGrade);
This is not best practice because they are only set once when the page loads. What if you had an HTML page with an area for a teacher to enter the student scores and when the teacher clicked a button, it triggered code in the studentMsg()
function to run? With variables like this in the global space, nothing would ever change regardless of what the teacher entered.
Also, the tests are not doing this:
console.log(studentMsg(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]), getGrade(37)));
They are doing this:
studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)
The latter passes in an array of student scores and a single student score. You can use your functions inside the studentMsg()
function.