Getting error on Review Javascript Fundamentals by building a gradebook app step 4

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";
}

function studentMsg(totalScores, studentScore) {
  const average = getAverage(totalScores);
  const grade = getGrade(average);
  if(grade == "F")
    {
      return "Class average: " + average + ". Your grade: " + grade + ". You failed the course.";
    }
    else{
      return "Class average:" + average+ " Your grade:"+ grade +" You passed the course.";
    }
    
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

This is the Error it shows
// running tests 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 the correct message based on the student’s score and the class average. // tests completed // console output Class average:71.7 Your grade:C You passed the course.

What does this mean
Sorry, your code does not pass. Keep trying.

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

That means that there’s an error here in what you’re returning.

Hi there, welcome to fcc community.

I re-formatted your code a bit for better readability.
This is your studentMsg function:

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

First of all, let’s take a look at this line:

const grade = getGrade(average);

I supposed you want to get the grade of the student based on his score, right?
If so, is average the right argument for getGrade function?

Secondly, please carefully re-check for dots (.) and spaces in the output messages to matched the required format.


For the next time, for better assistance, you should create a pre-formatted help post to the forum by pressing the Help button. This button only appears after you tried to summit the code 3 times.

image

And to post your code to the forum, put your code between 2 line of ``` (3 back ticks) (the back tick key is usually under the Esc key on your keyboard), like this:

```
# your code here
```

or you can use the Preformatted Text button:


Still the error is there

what does is even mean an average of 71.1 shouldnt get a grade of F since it passed

71.1 is class average.

The student score is 37. So his grade is : F

Please share your updated code.

Thank you for the assist i got it finally

1 Like