Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Tell us what’s happening:

It’s claiming the first “else if” is an unexpected token. I don’t know what that means or what i’m doing wrong. Other forums aren’t helping. Google isn’t helping.

Your code so far

function getAverage(scores) {
  let sum = 0;

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

  return sum / scores.length;
}

// User Editable Region

function getGrade(score) {
if (score == 100) {
  return "A++";
} else if (score >= 90 && <= 99) {
  return "A";
} else if (score >= 80 && <= 89) {
  return "B";
} else if (score >= 70 && <= 79) {
  return "C";
} else if (score >= 60 && <= 69) {
  return "D";
} else {
  return "F";
  }
}
console.log(getGrade(96));
console.log(getGrade(82));
console.log(getGrade(56));

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Welcome to the forum @dylantaylor410

SyntaxError: unknown: Unexpected token (16:26)
14 | if (score == 100) {
15 | return “A++”;
16 | } else if (score >= 90 && <= 99) {
| ^
17 | return “A”;
18 | } else if (score >= 80 && <= 89) {
19 | return “B”;

The message is giving you information about where the syntax error is located.

What is the comparison for the second part of the condition?

Happy coding

1 Like

edit: so while I got the error fixed after reading it, I don’t actually get why it was an error. I told it “greater than or equal to 90, or less than or equal to 99.” I don’t get why that would have been an error to begin with.

the <= operator needs a value on both side, you put a value only on the right, so you get a syntax error

what confuses me there is that I did have the >= on the left, and I didn’t need it on both sides- the code passed after I removed the one on the right entirely. The passing code didn’t have a <= at all.

Ultimately the code passed, i’m just annoyed that it was something so simple- something I don’t actually understand at all, lol.

you have score on the left and 90 on the right, there is a value on both sides of the >= operator

when you use && you need a complete expression on both sides, and <= 99 is not a complete expression

Even still, it doesn’t explain why it was telling me “else if” was wrong before. It’s doing it again on the next lesson, it’s just saying that “else if” needs to be removed.

open a new topic for the next step

for the error you were getting it was showing this:

SyntaxError: unknown: Unexpected token (16:26)

  14 | if (score == 100) {
  15 |   return "A++";
> 16 | } else if (score >= 90 && <= 99) {
     |                           ^
  17 |   return "A";
  18 | } else if (score >= 80 && <= 89) {
  19 |   return "B";

it’s pointing at line 16 with the > but it’s pointing at the <= operator with the ^ showing exactly where the issue is

Also the (16:26) is a way to say where, line 16, character 26