Hi everybody, please help me with this last step to the Javascript gradebook app step 4, I’m not sure what’s wrong with the solution I’ve provided:

/*
//steps to complete
Complete the `studentMsg` function with `totalScores` and `studentScore` for parameters. The function should return a string representing a message to the student.

``````If the student passed the course, the string should follow this format:

```
```

If the student failed the course, the string should follow this format:

```
```

Replace `average-goes-here` with the average of the total scores. Replace `grade-goes-here` with the student's grade.

**Tips**

* Use the `getAverage` function to get the class average.
* Use string concatenation (`+`) to build the message.
* Be careful with the punctuation and spaces in the message.
``````

*/

//My solution:
function getAverage(scores) {
let sum = 0;

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

return sum / scores.length;
}

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 studentMsg(totalScores, studentScore) {
const average = getAverage(totalScores);

return "Class average: " + average.toFixed(2) + ". Your grade: " + grade + “. You passed the course.”;
} else {
return "Class average: " + average.toFixed(2) + ". Your grade: " + grade + “. You failed the course.”;
}
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

I’ve got it, I don’t know why I was rounding off the average:

return "Class average: " + average + ". Your grade: " + grade + “. You passed the course.”;
} else {
return "Class average: " + average + ". Your grade: " + grade + “. You failed the course.”;
}
}

1 Like

Hello;
Did you pass with this code?

Because your `hasPassingGrade()` function doesn’t return `getGrade()` function returning value. And if you control `grade` variable is not equel `F`, it will always return true. Because grade never take the letter value, it is take the result of `getGrade()` function control.

Hi there, and thank you for the feedback. I think the problem was me trying to round off with .toFixed… I removed .toFixed from the code and it passed.

return "Class average: " + average + ". Your grade: " + grade + “. You passed the course.”;
} else {
return "Class average: " + average + ". Your grade: " + grade + “. You failed the course.”;
}

Sorry for misdirection.
You’re right, let me correct that. The `hasPassingScore` function only returns a boolean value, while the `grade` variable holds the letter value. There’s no error in your code passing. Just you don’t use your `hasPassingGrade` function but I didn’t realize it correctly.

And also next time please don’t forget to send your codes with ‘preformatted text’ for better understand.
You can reach this with `</>` button in text editor or you can use `ctrl+e` shortcut.

Happy coding!

I didn’t know about the ‘preformatted text’, I was wondering why sometimes my code doesn’t even get displayed properly lol, I’ll do that next time.
And thank you once again.

1 Like