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.
if(score===100){
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"
  }
}

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

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 2

1 Like

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.

2 Likes

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

3 Likes

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

2 Likes

Hey, How about this?

it doesn’t pass the test

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

1 Like

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 (').

1 Like
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:

1 Like

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

2 Likes

your number is 82, what ahppens here?

1 Like

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

2 Likes

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

1 Like

am stuck here, can anyone help me out.

Score Range Grade
100 A++
90 - 99 A
80 - 89 B
70 - 79 C
60 - 69 D
0 - 59 F
1 Like

am stuck here, I need help.
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 <= 79 && score >= 70 ){
return “C”;
}else if (score <= 69 && score >= 60){
return “D”;
}else if (score <= 59 && score >= 0){
return “F”;
}
}
}

1 Like

Am stuck here, I need a guide
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 <= 79 && score >= 70 ){
return “C”;
}else if (score <= 69 && score >= 60){
return “D”;
}else if (score <= 59 && score >= 0){
return “F”;
}
}
}

1 Like

hi, seems the condition for return “A” and return “B” is not as required, try
solution redacted

1 Like

thanks a lot, I appreciate

1 Like

hey @YzhaLing

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

2 Likes

am stuck here.
` function hasPassingGrade(score) {
if (score => “A”) {
return true;
}else if (score => “F”) {
return false;

}
} `

1 Like

hey @enyereibechibueze please open your own topic

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like