My hasPassingGrade function passes all tests except #19 (FreeCodeCamp Gradebook App)

Hey everyone :waving_hand:

I’m working on the Gradebook App challenge

All my tests pass except for test #19, which says:

“Your hasPassingGrade function should return false if the grade is an ‘F’.”

const getAverage = (arr) => {
  let total = 0;
  for (let i = 0; i < arr.length; i++) {
    const grade = arr[i];
    total += grade / arr.length;
  }
  return total;
};

const getGrade = (grade) => {
  if (grade === 100) return 'A+';
  else if (grade >= 90 && grade <= 99) return 'A';
  else if (grade >= 80 && grade <= 89) return 'B';
  else if (grade >= 70 && grade <= 79) return 'C';
  else if (grade >= 60 && grade <= 69) return 'D';
  else return 'F';
};

const hasPassingGrade = (score) => score !== "F"

const studentMsg = (scores, studentScore) => {
  const avgScore = getAverage(scores);
  const grade = getGrade(studentScore);
  const passing = hasPassingGrade(grade);
  return passing
    ? `Class average: ${avgScore}. Your grade: ${grade}. You passed the course.`
    : `Class average: ${avgScore}. Your grade: ${grade}. You failed the course.`;
};

So, in the console it behaves exactly as expected — but test #19 still fails.

Does anyone know why FreeCodeCamp might not be accepting this test?

Thanks in advance :folded_hands:

The hasPassingGrade function should use the getGrade function to get the letter grade, and use it to determine if the grade is passing. A passing grade is anything different from "F".

Please review User Story #4.

1 Like

Hi @denis-mahei and welcome to our community!

I’ve edited your post to include a direct link to the lab, as otherwise it can be tricky to debug your code.

You appear to have confused grade and score a little within your app. The grade is a letter (A to F), whilst the score is the numerical mark attained.

Your hasPassingGrade function should take a numerical score as a parameter but then return true or false depending on what grade that score achieves. You can call another function within hasPassingGrade, to achieve this.

1 Like

Really appreciate the guidance!

1 Like