My code is not being accepted in codecademy's exercise

am currently learn a full-stack dev career path. So I’ve reached some series of quiz (about javascript functions)
and the quiz was :
-Write a function, finalGrade(). It should:

take three arguments of type number
find the average of those three numbers
return the letter grade (as a string) that the average corresponds to
return ‘You have entered an invalid grade.’ if any of the three grades are less than 0 or greater than 100
0-59 should return: ‘F’
60-69 should return: ‘D’
70-79 should return: ‘C’
80-89 should return: ‘B’
90-100 should return: ‘A’
my code’s
function finalGrade(grade1, grade2, grade3) {

if ((grade1 < 0 || grade1 >100) || (grade2 < 0 || grade2 > 100) || (grade3 < 0 || grade3 > 100)) {

return 'You have entered an invalid grade'


const sum = grade1 + grade2 + grade3;

const average = sum / 3;

if (average <= 59) {

return 'F'

} else if (average <= 69) {

return 'D'

} else if (average <= 79) {

return 'C'

} else if (average <= 89) {

return 'B'

} else {

return 'A'


but am stuck coz I didn’t use the same code as they expected me to… and am sure my code’s doing what they asked me to. so the question here is: Do I have to accept to copy their solution while I know I’ve not done any mistake?


Could you format your code with the </> button if you have a chance?

It seems to run fine, can you put a link to the exercise? What exactly does the grader tell you is wrong?


I’ve been trying but seems something’s wrong.

The link’s:
The grader is telling me that:" If any of the grades passed in are less than 0 or greater than 100, the function should return ‘You have entered an invalid grade.’1"

You’re going to hate it but you’re missing a period at the end of You have entered an invalid grade.

On the bright side it is a good highlighter of needing to check expected output format strictly (as sometimes other programs depend on specific formatting).

:grimacing: Thanks a lot… I was so confused.

1 Like