Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Tell us what’s happening:

I put the first else if (90<=score<=99) for “A” but still passing the test for 82 and 56.
return “A++”
} else if(90<=score<=99){
return “A”
console prints A for all test. shouldn’t the test be A and two undefined?

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(90 <= score <=99){
    return "A"


// 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/ Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 2

sorry, “test” I mean the console printed results. but if I use only > and < in condition, it worked. don’t know why can’t use 90 <= score <= 99 :thinking:

Hi @YzhaLing !

Welcome to the forum!

In JavaScript you can’t do this

Maybe that works in other languages, but it won’t work here in JS.

1 Like

Ah~ Thank you! I get that, if I put if(score <= 99 & score >= 90), it works. :sweat_smile: get it. :pray: :pray:

1 Like

the AND operator is &&
only one & is a different operator

1 Like

Hey, How about this?

it doesn’t pass the test

“else if(score >= 80 && score <= 89){
return “B”;

please post all the code, just a snippet is pretty difficult to debug

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

function getGrade(score) {
if(score === 100){
  return "A++";
}else if(score <= 99 || score <= 90){
  return "A";
} else if(score >= 80 && score <= 89){
  return "B";
}else if(score === 78){
  return "C"
}else if(score <= 69 || score <= 60){
  return "D"
}else if(score <= 59
  return "F"

Don’t mind the rest of the code. I am trying to understand why the condition of 80 - 89 is not working :slight_smile:

take a close look at what you wrote here

that is where your issue is

Right now you are saying any score that is less then 99 should get an A
but that is not the correct logic

1 Like

your number is 82, what ahppens here?

the test passed so I thought it was fine. but I saw the mistake. thanks for you help

1 Like

ah, absolutely right, thanks for the reminding :+1: