Build a Gradebook App

are you giving the right value to hasPassingGrade now?

So:

if (hasPassingGrade(score) {

Yes! That should pass.

It does, but now 23 - 26 are not passing

Please post all of your updated code.

Tests:

  • Failed:23. 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 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(score) {
  if (getGrade(score) !== "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.";
  }
}

So, start with the first failing test, and test your code by adding this to the bottom of your script file:

console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));

What do you see in the console? Compare that to what is expected and check your code to see where you it is checking if the student passed. What can you change to fix that?

So like this:

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(score) {
  if (getGrade(score) !== "F") {
    return true;
  } else {
    return false;
  }
}

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

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

I also have something to say:

Your new update for freeCodeCamp sucks. Because I cant tell where I left off because of the white circles. I miss the old freeCodeCamp.

what white circles?
I can clearly see what I have completed and what I haven’t

image

if you don’t see this, please test by deactivating your browser extensions

Oh my god, I am so sorry. It was a browser extension.