Review JavaScript Fundamentals by Building a Gradebook App - Step 4 Error

Tell us what’s happening:

My code works just fine. However, the console tells me I should be getting different values, and this is due to the fact that the console log has different values (console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)):wink: as the one it believes I should be logging (which is:
studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100))
Did I do something wrong, or should I add the console log its telling me I need to have? Please help!

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

// 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/125.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Wrong argument for the hasPassingGrade function.

1 Like

Shouldn’t the value of hasPassingGrade(getGrade) be a boolean of true or false? What am I missing (with out giving away the answer, of course).

Take a look at the definition of the hasPassingGrade function:

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

This function takes one argument: score - which is the student’s score - an integer number.

For example:
If the student’s score is 39 then

hasPassingGrade(39);

or

const studentScore = 39;
hasPassingGrade(studentScore);

will return false.


In your code, getGrade is a function name, not an interger variable.
The argument should the the variable that hold the student’s score.

2 Likes

still a little bit confused. should i use const score to define it before using or is it better to use another variable (e.g. studentScore)?

no, you need to use the variable you have in the studentMsg function that contains a single integer number

It’s just an example to demonstrate that the student’s score may be stored inside an variable.

Inside the studentMsg function, the student’s score is already provided through the argument studentScore.

So you can use the variable studentScore as an argument for the hasPassingGrade function.

It’s just like to get the student’s grade (A, B, C, D, E, F), you passed the studentScore variabe to the getGrade function: