Review JavaScript Fundamentals by Building a Gradebook App - Step 3

Tell us what’s happening:

Can you please tell me what I am doing wrong. Do I put the if statements in the function (I tried and it turned grey)

Thanks
Iskren

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) {
  return score;
}

if(score===A++){
  console.log(true);
} else if (score===A){
  console.log(true)
} else if (score===B){
    console.log(true)
} else if (score===C){
    console.log(true)
} else if (score===D){
    console.log(true)
} else if (score===F){
    console.log(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/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 3

You need to call getGrade function inside of your new hasPassingGrade function. Do not create a new getGrade function. Call the existing one with score parameter.

If getGrade function returns “F”, it means hasPassingGrade function needs to return False. Otherwise it will return True.

1 Like

I called the passingGrade function inside the function, I returned the score inside the function and I put the if statement inside the function

That return score didn’t do anything. Reset the challenge step and add an if…else block. In the if condition check, if the student score has passing grade using getGrade() function. If pass return true in the if block, return false in the else block.

Always post your updated code, when it not works. Using preformatted text option in the reply setting menu.

Ok, this is my updated one

function hasPassingGrade(score) {
if(getGrade()){
console.log(true);
} else if (getGrade()){
console.log(true)
} else if (getGrade()){
console.log(true)
} else if (getGrade()){
console.log(true)
} else if (getGrade()){
console.log(true)
} else (getGrade())
console.log(false);
}
}

You only need one pair of if…else block. In the if condition use getGarde() with score parameter and check it with grade "F", using equal or not equal operator. Based on the condition in the if and else block, return true and false in each block. Remember, the console log didn’t return the value. returning value needs the return keyword.

function hasPassingGrade(score) {
if(getGrade()!= F){
return true;
} else (getGrade()===F)
return false;
}

you need to give an argument to getGrade

it says cant find variable F

Else block didn’t need the condition. And pass the argument in the if condition getGrad() function is empty.

Give the getGrade function score argument.
Use === not =.
And wrap F between quotes.

It says
Your hasPassingGrade function should return true if the grade is an "A"

isn’t that what this means:
if(getGrade()!= “F”){
return true;

function hasPassingGrade(score) {
if(getGrade()!= “F”){
return true;
} else (getGrade()===“F”)
return false;
}

its all fine, I got it correct, thanks alot

you need an argument for getGrade, without that it doesn’t know which score is being converted