There is a bug in this lesson. The second call of the function “studentMsg” is not in the script.js. I checked everything and I can’t pass this lesson.
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 (hasPassingGrade(getGrade(studentScore))) {
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([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 4
you don’t need to pass in getGrade with an argument of studentScore
remember that hasPassingGrade accepts a score.
also, remember that hasPassingGrade already calculates the grade for you. So you don’t need to calculate again with that function call.
I found that passing the studentScore parameter as the parameter for hasPassingGrade function call in the if statement worked. I believe that is what was said above, but it still confused me a bit. Only posting this in case it also seemed to confuse anyone else.
It might help to look at what hasPassingGrade does to better understand.
So hasPassingGrade takes in a score which is a number and calls the getGrade function.
The getGrade function then takes that number score like 72 or 88 for example and returns a grade like C or B.
It then compares that letter grade to check if it is an F
if it is an F then that means the student has failed.
Otherwise, the student has passed.
So that is why you can use the if statement to check if the student is passing and return the appropriate message
I PASSED the test. But it does not make sense to me
Am i missing something…
this is the input…part of the provided code
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
this was my output
Class average: 71.7. Your grade: F. You failed the course.
if my average is 71,7… a passing average grade
and studentScore is 37 and “F”
isn’t the average score that determins if u passed a COURSE? lol
or did the teacher just not like this student?