Theres 2 things happening here that I cant seem to figure out.
First, the A++ array isnt even showing up until the “sorry your code does not pass” error pops up so im copying pasting it from there to console.log (not sure if there is a bug in this lesson.
Second, I cant figure out the last part on what Im doing wrong. Theyre either both passing or both failing.
// console output
Class average: 50.8. Your grade: A++. You passed the course.
Class average: 71.7. Your grade: F. You passed the course.
Your code so far
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 hasPassingGrade(score) {
return getGrade(score) !== "F";
}
// User Editable Region
function studentMsg(totalScores, studentScore) {
if (getGrade) {
return "Class average: " + getAverage(totalScores) + "." + " Your grade: " + getGrade(studentScore) + "." + " You passed the course."
} else {
return "Class average: " + getAverage(totalScores) + "." + " Your grade: " + getGrade(studentScore) + "." + " You failed the course."
}
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 4
well it has the if /else with operators but I dont understand how to translate it to passing or failing onto the string. ive been stuck here for 3 days
Hi, ive tried using studentScore which is the 2nd parameter in studentMsg and it gives me the same error, that it isn’t defined. such as if i were doing:
if (getGrade(studentScore)) {} instead of just if (getGrade) {}
oh theres one called hasPassingGrade at the bottom but im unsure how to use it. Ive plugged it in and it doesnt do anything.. ive also returned it as well within the studentMsg function
heres the output i get with (getGrade)
// console output
Class average: 50.8. Your grade: A++. You passed the course.
Class average: 71.7. Your grade: F. You passed the course.
my code:
function studentMsg(totalScores, studentScore) {
if (getGrade) {
return “Class average: " + getAverage(totalScores) + “.” + " Your grade: " + getGrade(studentScore) + “.” + " You passed the course.”
} else {
return “Class average: " + getAverage(totalScores) + “.” + " Your grade: " + getGrade(studentScore) + “.” + " You failed the course.”
}
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
The purpose of getGrade() is just to get the letter grade associated with the score. That’s all it does. It does not tell you if the student’s score is a passing or failing score.
You were so close when you used the correct function. You just needed to use the score parameter passed in to studentMsg().
thank you so much!! this was it man i was breaking my head here on this one. I really appreciate all your help! – when you told me i was hrd coding it, i didnt realize i was doing that at that point