Build a Gradebook App

Hello! I can’t understand why my code doesn’t pass, as it seems to work fine when I test in the console, but test 17, which is about the hasPassingGrade function does not pass.

function getAverage(scores) {
  let studentScore = 0;
  for(let score of scores) {
    studentScore += score / scores.length;
  };
  return studentScore;
}

function getGrade(studentScore) {
  let grade = "";

  switch(true) {
    case studentScore === 100:
      grade =  "A+";
      break;
    case studentScore >= 90:
      grade =  "A";
      break;
    case studentScore >= 80:
      grade =  "B";
      break;
    case studentScore >= 70:
      grade = "C";
      break;
    case studentScore >= 60:
      grade = "D";
      break;
    default:
      grade = "F";
  };

  return grade;
}

function hasPassingGrade(grade) {
  let hasPassed;

  grade !== "F" ? hasPassed = true : hasPassed = false;
  return hasPassed;
}

function studentMsg(scores, studentScore) {
  let average = getAverage(scores);
  let grades = getGrade(studentScore);
  let hasPassed = hasPassingGrade(grades);
  let message;

  if(hasPassed === false) {
    message = `Class average: ${average}. Your grade: ${grades}. You failed the course.`;
  } else {
     message = `Class average: ${average}. Your grade: ${grades}. You passed the course.`;
  }

  return message;
}



console.log(hasPassingGrade("F"));
console.log(hasPassingGrade("A+"));

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));

Hi there. Also post a link to the challenge step.

Of course, sorry, the link.
Test * 17. Your hasPassingGrade function should return false if the grade is an "F".

You shouldn’t have an assignment like this in a ternary. This is also way more complicated than it should be.

Your logic is:
If (grade !== “F” ) is TRUE then assign TRUE to hasPassed and then return hasPassed
If (grade !== “F” ) is FALSE then assign FALSE to hasPassed and then return hasPassed

Can you see a way to simplify this logic?

I simplifed the logic, it still pass on my console, but not on FCC.
This intrigues me since all the tests except the 17 pass.

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

Love it.

In a situation like this you should go back to the User Stories and make sure you did the correct thing.

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.

Note: score vs. grade.

I changed grade to score but it is still not passing.

it isn’t the parameter name the issue. What is a score and what is a grade? what’s the difference between the two?

Thanks a lot! It helped me think about what I was doing wrong, now I used the actual score it was asking haha and also had to change how the function was being called in the studentMsg and it all passed! Thank you!