Review JavaScript Fundamentals by Building a Gradebook App - Step 3

Tell us what’s happening:

Don’t understand why the true boolean is working but the false is not…

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) {
  if (getGrade === "A++", "A", "B", "C", "D") {
    return true;
  } else if (getGrade === "F") {
    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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 3

neither are working

getGrade is a function, you are not using it correctly


here you are comparing a function with a string, this is always false


when you separate expressions like this with the comma, the value of the total expression is that of the last expression, see comma operator for more info.
that means this is equivalent to if ("D") {}, a string is truthy, so this executes, making so that you always return true.


here you are also comparing a function with a string, this is always false

1 Like

Hey thanks for the help.
I’m still stuck tho. I get the comma problem so I removed it, and I also removed the “” so it would not be a string anymore, but I have no success yet.

what is your code now?

none of your strings would be a good value without quotes, I don’t understand what change you made

my code so far:

if (getGrade = "A") {
  1. Functions need to be called with parantheses (). Example: myFunction() would call the function named myFunction, that does not have taken any arguments. To call a function with an argument, place it inside the parantheses, myFunction(argument).
  2. The single equal sign = is the assignment operator. Here you are trying to assign the string “A” to a variable called getGrade. You should use === in this context.
1 Like

@SpookyBlump thanks for the tips. I’m still stuck tho :frowning
Don’t what else to do, so if you have more tips, here’s my code so far:

I suggest you try to follow @SpookyBlump tips, I don’t see any changes in your code

oops, I send the wrong print…

function hasPassingGrade(score) {
  getGrade(score);
  if ("A") {
    return true;
  } else if ("B") {
    return true;
  } else if ("C") {
    return true;
  } else if ("D") {
    return true; 
  } else if ("F") {
    return false;
  }
}
  let score = getGrade();
console.log(hasPassingGrade(100));
console.log(hasPassingGrade(53));
console.log(hasPassingGrade(87));

good, you are calling the function, but now what are you doing with its output?

I thought I need to check if they are passing grades or no using the if and else if…

return true if getGrade is not equal to "F". else return false.

Or explicitly return if score is more then or equal to 60.

yes, you do, but that means you need to do a comparison. Your condition is only a string tho, you are not doing any comparison