Build a Gradebook App

Tell us whats happening:

Test 19 still fails even though F returns false

Your code so far:

function getAverage(arr) {
  if (arr.length === 0) return 0;

  let sum = 0;
  for (let i = 0; i < arr.length; i++) {
    sum += arr[i];
  }

  return sum / arr.length;
}

function getGrade(score) {
  if (score === 100) return "A+";
  if (score >= 90) return "A";
  if (score >= 80) return "B";
  if (score >= 70) return "C";
  if (score >= 60) return "D";
  return "F";
}

function hasPassingGrade(grade) {
  return grade !== "F";
}

function studentMsg(scores, studentScore) {
  const average = getAverage(scores);
  const grade = getGrade(studentScore);

  if (hasPassingGrade(grade)) {
    return "Class average: " + average +
           ". Your grade: " + grade +
           ". You passed the course.";
  } else {
    return "Class average: " + average +
           ". Your grade: " + grade +
           ". You failed the course.";
  }
}

Build a Gradebook App: Build a Gradebook App | freeCodeCamp.org

I’ve edited your post to improve the readability of the code and to replace the link in the topic heading, which I added to the bottom of your post.

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Please review User Story #3 and #4 to make sure you have implemented hasPassingGrade() as asked.

What parameter should it take? What function should you use inside the body of the function?

I still dont get it. 3 and 4 are passing, but 19 is not.

A user story is not the same as a test. Please re-read user stories 3 and 4. Thank you.

I tried. But it still did not work.

Please post your updated code.

function getAverage(arr) {
  if (arr.length === 0) return 0;

  let sum = 0;
  for (let i = 0; i < arr.length; i++) {
    sum += arr[i];
  }

  return sum / arr.length;
}

function getGrade(score) {
  if (score === 100) return "A+";
  if (score >= 90) return "A";
  if (score >= 80) return "B";
  if (score >= 70) return "C";
  if (score >= 60) return "D";
  return "F";
}

function hasPassingGrade(grade) {
  if (grade !== "F") {
    return true;
  } else {
    return false;
  }
}

function studentMsg(scores, studentScore) {
  const average = getAverage(scores);
  const grade = getGrade(studentScore);

  if (hasPassingGrade(grade)) {
    return "Class average: " + average +
           ". Your grade: " + grade +
           ". You passed the course.";
  } else {
    return "Class average: " + average +
           ". Your grade: " + grade +
           ". You failed the course.";
  }
}

have you reviewed what the user stories say about hasPassingGrade?

Yes, I have. But it is so confusing.

what do you find confusing? if you tell us we can help you clear the doubts

It says :
" 1. 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"."

I wrote exactly what it told me to write:

function hasPassingGrade(grade) {
  if (grade !== "F") {
    return true;
  } else {
    return false;
  }
}

are you sure? you are not using the getGrade function here

What about this:

function hasPassingGrade(grade) {
  if (getGrade(score) !== "F") {
    return true;
  } else {
    return false;
  }
}

you are writing getGrade(score), where is the variable score coming from?

Then…

function hasPassingGrade(grade) {
  if (getGrade(grade) !== "F") {
    return true;
  } else {
    return false;
  }
}

Please read User story #3 carefully. What does is say your parameter should be?

considering that hasPassingGrade is not receiving a grade as argument I would not use grade as a parameter

but what do the tests say?

The tests pass. But now 23, 24, 25, and 26 are failing

Tests 23 - 26:

    1. studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100) should return the following message: "Class average: 50.8. Your grade: A+. You passed the course.".
  • Failed:24. studentMsg([12, 22, 32, 42, 52, 62, 72, 92], 85) should return the following message: "Class average: 48.25. Your grade: B. You passed the course.".

  • Failed:25. studentMsg([15, 25, 35, 45, 55, 60, 70, 60], 75) should return the following message: "Class average: 45.625. Your grade: C. You passed the course.".

  • Failed:26. Your studentMsg function should return the correct message based on the student’s score and the class average.

My code:


function studentMsg(scores, studentScore) {
  const average = getAverage(scores);
  const grade = getGrade(studentScore);

  if (hasPassingGrade(grade)) {
    return "Class average: " + average +
           ". Your grade: " + grade +
           ". You passed the course.";
  } else {
    return "Class average: " + average +
           ". Your grade: " + grade +
           ". You failed the course.";
  }
}

Is this good:

function hasPassingGrade(score) {
  if (getGrade(score) !== "F") {
    return true;
  } else {
    return false;
  }
}