Need some help with Code Challenges, finalGrade()

I’ve completed the introductionary JavaScript course and decided to continue with the challenges to practice my skill. I found out that I need it! Case in point this finalGrade() assignment. I know I can make this assignment better by having the code stop when it encounters an illegal grade before calculating averages, but it should work the other way around, even though this code of mine is bulkier.

This code returns an unusual error message that I cannot trace to the code. The error message being:


The problem seems obvious, I need to remove a bracket ) but I cannot find it! The code in question:

function finalGrade (grade1, grade2, grade3) {

  let averageGrade;

  if((grade1 >= 0 && grade1 <= 100) ||

     (grade2 >= 0 && grade2 <= 100) ||

     (grade3 >= 0 && grade3 <= 100)) {

      averageGrade = ((grade1 + grade2 + grade3)/3);

      if (averageGrade >= 0 && averageGrade <= 59) {

        return 'F';

      } else if (averageGrade >= 60 && averageGrade <= 69) {

        return 'D';

      } else if (averageGrade >= 70 && averageGrade <= 79) {

        return 'C';

      } else if (averageGrade >= 80 && averageGrade <= 89) {

        return 'B';

      } else if (averageGrade >= 90 && averageGrade <= 100) {

        return 'A';

      } else {

        return 'You have entered an invalid grade.';



By the way, if anyone can explain why and/or if it’s better to start a function with const or function, that would be appreciated too.

you don’t need to remove a parenthesis, but add a curly brace.
Could you add a link to the challenge, please? Is that in the Code challenges (Beta)? I didn’t see it there…

It’s found in code challenges JavaScript fundamentals. I assum you need a link; I’m afraid to say you’ll going to have to tell me how…

Just copy paste the link from the URL, please…

That I can do…

1 Like

You want all three arguments to be within the range 0-100, right? With your if clause, the code runs when just one argument is between 0 and 100.

1 Like

Thanks. I’ve seen the hint do something similar to my code, but I guess I’ll have to check again. I’ll also check if this resolves my syntax error.

That resolves your syntax error…

Found it! I should have checked every brace, including the one I thought had to be fine. Now off to your tip on my OR mistake…

EDIT: And found that too, thanks. The hint is based on code that kicks out erroneous grades first before proceeding. In that case, OR’s all around are fine. My code checks if all grades are between 0 and 100 and then proceeds with the averages, ELSE should trigger when the grades are not between 0 and 100. Let’s see if I can take it from here.

1 Like