Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Hello guys, I think the test here is wrong and it’s flagging my code and incorrect. Please let me know if the error is otherwise from my code because the msg from the console is also wrong. here is my code.
return hasPassingGrade(getAverage(totalScores) + studentScore/ totalScores.length + 1 ) ? Class average: ${getAverage(totalScores) + studentScore/ totalScores.length + 1 }. Your grade: grade-goes-here. ${getGrade(getAverage(totalScores) + studentScore/ totalScores.length )}. You passed the Error msg from test Your function call of studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)should return the following message:“Class average: 71.7. Your grade: F. You failed the course.”` .

and the msg from console is :
Your function call of

studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)

should return the following message:

"Class average: 71.7. Your grade: F. You failed the course."

. Your function call of

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."

. Your

studentMsg

function should return a the correct message based on the student’s score and the class average. // tests completed // console output Class average: 76.4. Your grade: grade-goes-here. C. You passed the course

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) {
    return hasPassingGrade(getAverage(totalScores) + studentScore/ totalScores.length + 1 ) ? `Class average: ${getAverage(totalScores) + studentScore/ totalScores.length + 1 }. Your grade: grade-goes-here. ${getGrade(getAverage(totalScores) + studentScore/ totalScores.length )}. You passed the course.`: `Class average: ${getAverage(totalScores) + studentScore/ totalScores.length + 1 }. Your grade: grade-goes-here. ${getGrade(getAverage(totalScores) + studentScore/ totalScores.length )}. 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/124.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

You need to replace grade-goes-here with the actual grade.

Also, it looks like you are overcomplicated the calculations here

For all of those functions, you only need to pass in one argument.
You don’t need to do any extra calculations like you are trying to do.

once I fix all of those things, then it passes for me

This is the error from the console

Your function call of

studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)

should return the following message:

"Class average: 71.7. Your grade: F. You failed the course."

. Your function call of

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."

. Your

studentMsg

function should return a the correct message based on the student’s score and the class average. // tests completed // console output Class average: 71.7.Your grade: F. You failed the course.

this is also the error I’m getting from the test:

Your function call of studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37) should return the following message: "Class average: 71.7. Your grade: F. You failed the course." .

I think there is a contradiction. That is why I tried to add the other number outside the array which made me use the complicated calc which gave total sum of all the numbers but test still failing

Can you explain further about the issue you are seeing on your end?

If we step away from the code for a second and just add up the numbers manually then it works out.

For example, this first one

If we get the average, it should be 71.7
and if the student has a score of 37, then they have failed the course

then for this second test case

if we get the average, it does come out to 50.8
And if the student gets a perfect score of 100, then that results in them passing the course.

So I am not sure what you mean by contradiction here
Could you provide more details on what you think the correct test case should be?
Because everything is working on my end

Code passed. I had a extra space on the false condition of the ternary operator

1 Like