Review JavaScript Fundamentals by Building a Gradebook App - Step 3

Tell us what’s happening:

Hello I have an issue with my code. I went to ChatGPT cause I have just been staring at it and it mentioned somewhere I should use a “.include”.

I don’t recall using this yet and I really do not want to “learn” it that way.

So could I get some help with this issue, it seems right to me as it checked the first “score” but wont continue to check the rest.

thank you for your time.

Your code so far

function getAverage(scores) {
  let sum = 0;

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

  return sum / scores.length;
}

function getGrade(score) {
  if (score === 100) {
    return "A++";
  } else if (score >= 90) {
    return "A";
  } else if (score >= 80) {
    return "B";
  } else if (score >= 70) {
    return "C";
  } else if (score >= 60) {
    return "D";
  } else {
    return "F";
  }
}


// User Editable Region

function hasPassingGrade(score) {
const pass = ["A++", "A", "B", "C", "D"]
if (getGrade(score) <= pass) {
  return true
}
  return false
}


console.log(hasPassingGrade(100));
console.log(hasPassingGrade(53));
console.log(hasPassingGrade(87));

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

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 3

1 Like

Hi there,

Please re-check the condition of your if statement.

The instruction gave a hint:

A passing grade is anything that is not an "F".

So, it’s doesn’t matter if the grade is A, B, C, or D as long as it NOT EQUAL TO "F"

1 Like

Yeah I just done it now by looking up the same issue I had (I didn’t know I could just paste the step I was on…)

I just got it sorted right before I realized it was only “F” I was looking for.

Side question, how come my way wouldn’t of worked? or how would I make it work? Using my array method to check if this had that and so on, interested to know.

Also thank you for helping anyways!

1 Like

getGrade(score) is returning a letter grade, correct?
and pass is an array…
So what happens when getGrade returns a F for eg. Your if statement will be:
if ( ‘F’ <= [“A++”, “A”, “B”, “C”, “D”])

What should this return that would be helpful here?

1 Like

I am still trying to wrap my head around some of the concepts, I feel like I get them then I lose it. Reading into it more it mentioned that I can’t compare a string to an array.

From what I now think I understand is that they are not the same data type so I cannot do that?

Sorry if that seems like a dumb question but it’s what I think I understand at the moment.

1 Like

Well, maybe you can compare them but what would be the purpose of comparing them? Can you explain how that would help solve the problem?

1 Like

If I can ask you to please give the OP a chance to think for themselves in future, as part of learning is at least trying to communicate ideas and work through the issues with them.

2 Likes

So what I was trying to achieve, from how I understood it was to got back to my function (getGrade) and go over where my A - D’s were (if’s & if else. statements) Then have those conditions meet back then to be brought forward to my new if statement. (if (score === 100) { return “A++”) then going to my new function to then see, if I had “A++” there then it should match and be true and so on with the other letters I had given it. I just had and else statement without including F in my list but that didn’t work either.

I completely looked over the question as it was my first thought. As I type it out to explain what it was I was trying to do, it didn’t sound too great now since I actually read the question to solve it.

But does that make sense what I was trying to do? Feel free to ask me to explain it again as it would be good for me to explain my thoughts and issues more clearly. in future.

1 Like

So you did manage to get the string grade. But the part that was wrong was how you were trying to compare it to the array. When trying to compare a string to the array there are multiple ways to do so, depending on what you’re comfortable doing. If you can’t recall how, then try to do a google search “in js how to compare a string to an array” and you will see various answers.
You certainly could make this method work, but as you found out earlier, it was easier to just check if the grade was an F.

1 Like

Yeah now I understand, I didn’t know I couldn’t do that before. I was kind of just seeing if it would work somehow.

I’ll look it up as soon as I done with this other issue now… lol

3 Likes