Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Tell us what’s happening:

I think I wrote the correct code but it failed and don’t know how to fix it.

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 && score <=99)
    {
      return 'A';
    }
    else if(score >= 80 && score <=89)
    {
      return 'B';
    }
    else if(score >= 70 && score <=79)
    {
      return 'C';
    }
    else if(score >= 60 && scire <=69)
    {
      return 'D';
    }
    else (score >=0 && <=59)
    {
      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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 2

hi there!
try with only first conditions in all if else statment.

Hello!
Does it mean only the below condition?

if (score === 100) {
return “A++”

no. i am talking about the all else if conditions should be only one, the first ones.

also remove the condition form else statment. that is not valid. else do not need the condition.

Oh I get it!
Thank you for your help!

1 Like

Hi there,

First of all, there is an extra closing curly braces (}) at the end of your function. Delete one.

function getGrade(score) {
}
}  <=== DELETE THIS

Secondly, there is a typo with the variable name on this line: scire

And you missed the variabe name here:

What’s is <=59?


Fix 3 mistakes and your code will pass.
On a side note, you should do as hasanzaib1389 said.

Because when score isn’t equal to 100, it’s of course will <= 99.
So, the condition of the else if: score >= 90 is enough, score <= 99 is unnecessary.
And so on.

Thank you for your kind advise.
I could pass this by following the advice.
Thank you!

1 Like