My code is passing all of the tests, except for #17, which wants the hasPassingGrade function to return false when the grade is “F”. I have tested the hasPassingGrade function with console.log and it is giving the expected output for all of the grades.
Your code so far
function getAverage(arr) {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum / arr.length;
}
function getGrade(score) {
if (score < 60) {
return "F";
} else if (score < 70) {
return 'D';
} else if (score < 80) {
return 'C';
} else if (score < 90) {
return 'B';
} else if (score < 100) {
return 'A';
} else return 'A+';
}
function hasPassingGrade(grade) {
return grade !== "F";
}
function studentMsg(arr, score) {
const grade = getGrade(score);
if (hasPassingGrade(grade)) {
return `Class average: ${getAverage(arr)}. Your grade: ${grade}. You passed the course.`;
} else return `Class average: ${getAverage(arr)}. Your grade: ${grade}. You failed the course.`;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
You should have a function named hasPassingGrade that takes a score as a parameter and returns either true or false depending on if the score corresponds to a passing grade.
Ok…? I’m not sure why you posted that at me, but did you look at the sentence I quoted? I quoted it on purpose because you are not quite doing what it says and need to compare what it says in your code that I quoted.
The sentence you quoted was irrelevant to my issue. I am well aware that the wording appears to indicate that it is, but the actual tests do not match up. If tests 15, 16, and 18 are passing then there is no reason that 17 should not pass as well.
I have solved the problem and it did not involve changing the function you referenced. Thank you for your time anyway.
You fixed the fact that you were not taking a score in that function?
Faulty logic. There’s a good reason why only 1 of those was failing. I see why you think this, but its due to how you misinterpreted the one sentence I quoted. Wording in coding can be one of the hardest things.
if your function does not do what is required, it can by chance pass some tests, and not pass others. It has to return true or false, sometimes it gives the right value with the wrong logic.
everything that is passed to the function is different from 'F' so it would always return true so 16 and 18 pass, while 17 fails because your function never returns false