Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

There is a bug in this lesson. The second call of the function “studentMsg” is not in the script.js. I checked everything and I can’t pass this lesson.

Your code so far

function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}

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

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


// User Editable Region

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(getGrade(studentScore))) {
      return "Class average: " + getAverage(totalScores) + ". Your grade: " + getGrade(studentScore) + ". You passed the course.";
    } else {
      return "Class average: " + getAverage(totalScores) + ". Your grade: " + getGrade(studentScore) + ". You failed the course.";
    }
  }

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

// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

HI @wadegg49 !

Welcome to the forum!

Your issue is here

you don’t need to pass in getGrade with an argument of studentScore

remember that hasPassingGrade accepts a score.
also, remember that hasPassingGrade already calculates the grade for you. So you don’t need to calculate again with that function call.

once you fix that, then it will pass

4 Likes

I found that passing the studentScore parameter as the parameter for hasPassingGrade function call in the if statement worked. I believe that is what was said above, but it still confused me a bit. Only posting this in case it also seemed to confuse anyone else.

2 Likes

HI @griffincrvig !

Welcome to the forum!

It might help to look at what hasPassingGrade does to better understand.

So hasPassingGrade takes in a score which is a number and calls the getGrade function.
The getGrade function then takes that number score like 72 or 88 for example and returns a grade like C or B.

It then compares that letter grade to check if it is an F

if it is an F then that means the student has failed.
Otherwise, the student has passed.

So that is why you can use the if statement to check if the student is passing and return the appropriate message

Hope that helps

1 Like

I PASSED the test. But it does not make sense to me
Am i missing something…
this is the input…part of the provided code
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

this was my output
Class average: 71.7. Your grade: F. You failed the course.

if my average is 71,7… a passing average grade
and studentScore is 37 and “F”

isn’t the average score that determins if u passed a COURSE? lol
or did the teacher just not like this student?

1 Like

I have the same problem and I feel like I didn’t do it wrong.
Also, it gives me the same output

this is the class average.
Not the student average.

When you get the average for the class of multiple students that is the result of overall how they did.

nope.
Because the average score is for the class.
not the student.

The second argument of the function call here, is the student score

hope that clears it up

A post was split to a new topic: Step 4 of gradebook app is not passing