Missing brace? And troubleshooting function syntax?

I clicked on “Get Solution” then copy/pasted this:

const finalGrade = (midterm, final, homework) => {
    if ((midterm < 0 || midterm > 100) || (final < 0 || final > 100) || (homework < 0 || homework > 100)) {
        return 'You have entered an invalid grade.'
    }

But I get helper error “SyntaxError: Unexpected token )”

Please how can the solution code be wrong, and how do I fix it please?

Not able to reproduce this error. Did find a missing brace, though.

Need to see the rest of your code. You may have an extra ) somewhere else.

where please is the missing brace? I see an opening brace and a closing brace so do not understand what is missing. I have both { and }.

There is no more code. I only pasted in my lesson what I pasted here in this forum. Thank you.

We can see two opening braces but only one closing brace.

I removed the opening brace after the if statement and do not get error messages now. How do I report a mistake in the codecademy solution? Mistakes in solutions make learning very difficult:(

Moving along in the solution I’m also finding difficulty here:

let average = (midterm + final + homework) / 3
THE CODE ABOVE IS FROM THE SOLUTION PROVIDED. When I paste it in main.js and Run, I get errors. So I changed it to this:
let average = ‘(midterm + final + homework) / 3’;
I don’t get errors when I run that but I’m not sure if it is correct. Can you confirm the solution for me please?

Moving along in the exercise, I’m trying to test my code by calling the function but it’s not working, please find my error? I’m testing my code like this:

console.log(finalGrade(50, 70, 5));

and below is my code in its entirety:

const finalGrade = (midterm, final, homework) => {
if ((midterm < 0 || midterm > 100) || (final < 0 || final > 100) || (homework < 0 || homework > 100))
return ‘You have entered an invalid grade.’
}

let average = ‘(midterm + final + homework) / 3’;
if(average<60){
return ‘F’
} else if(average<70){
return ‘D’
} else if(average<80){
return ‘C’
} else if(average<90){
return ‘B’
} else {
return ‘A’
};

console.log(finalGrade(50, 70, 5));

THANK YOU!

You need the { after the if(condition) statement. The code to run when the if(condition) evaluates to true should be in a code block encased in {}:

if(a + b === c) {
  //code to execute if true
} else {
  //code to execute if false
}

When @mtf said you were missing a }, he was referring to the one at the very end of the finalGrade function:

const finalGrade = (parameters) => {
  //function code goes here for example:
  if(a + b === c) {
    //code to execute if true
  } else {
    //code to execute if false
  }
  return something;
`}` 
1 Like
if ((midterm < 0 || midterm > 100) || (final < 0 || final > 100) || (homework < 0 || homework > 100)) `{` 
return ‘You have entered an invalid grade.’
}

You are missing the open curly brace following the if(condition).

let average = `‘`(midterm + final + homework) / 3`’`;

The value assigned to the average variable should not be encased in quotes. You are later comparing it to numbers: average<60 and so on. You need average to be a number not a string.

return ‘F’`;`
return ‘D’`;`
return ‘C’`;`
return ‘B’`;`
return ‘A’`;`

These statements should end with a ;

if(average<60){
return ‘F’
} else if(average<70){
return ‘D’
} else if(average<80){
return ‘C’
} else if(average<90){
return ‘B’
} else {
return ‘A’
}; //This curly brace closes your last else code block.
`}` //You need this one to close the function. This is the one missing from the beginning.

Good luck! Hope this helps!