Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

JS building a gradebook step 4,
my function call should return class average 71.7: ect ect
so, an if statement executes a block of code if a specified condition is true. so else would say that my block of code is false. It’s not really false just because you failed the course. so how would i make this logical? what am i missing here ?

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";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}


// User Editable Region

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(studentScore)) { 
  return ( "class average:  " + getAverage(totalScores) + " .yourGrade:" + getGrade(studentScore) + " .you passed the course"
  
}

// User Editable Region

if { 
  return ( "class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + " .you failed the course"
} 

}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

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 Edg/124.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

you should use an if else statement.
Just to remind you what that would look like in a general case:

if (something is true) {
  do something when its true
} else {
  do something else when it is not true;
}

Edit: also you returned message should be EXACTLY the same as the one they want. (include all spaces, capitals etc)

if else statement specifies a new condition to test if the first condition is false. What would be false about the return function. do you think i need to have a let variable so it can be reassigned.

You’ve misunderstood how if-else works.
Let me show you more examples:

if (hour < 18) {
  greeting = "Good day";
} else {
  greeting = "Good evening";
}

The conditional is something the if statement checks to see if it is a truthy or a falsey.
In your case, the function hasPassingGrade will either say yes (true) or no (false).

so, the output “good evening” is not a false statement , it is just < 18 ,
so !== any grade that is passing is true, any grade that is failing is false

For your case you don’t need === or !==
Because your function will return a Boolean.

I still need a hint that can push my code into being passable, what am i not seeing here

I gave you several hints already?
1- use if else statement
2- your condition is the result of the hasPassingGrade
3- your message should match exactly the expected message from spaces to capitals and punctuation.

If you are still stuck, please show us how you changed the code with the above hints given to you and we can give you more guidance as needed.

1 Like

When a bracket has a red line under it does that mean the block of code has an error or the bracket itself has a problem

i think it means something is not matched up (like a bracket cannot be matched to its partner)

{ } matched
{
{ not matched ?
all examples I’m seeing have the same set up with the bracket as I do. I’m just not getting what part of the code I’m supposed to try differently.

i don’t really see what I’m supposed to look into? to figure out? from an underlined bracket,
I just want to be able to identify what is actually wrong with the code so I can work on that issue.
am I missing a period do i have a white space somewhere.
why is my condition a result of has Passing grade when that passing grade is outside of the array. [ 81, 22, 33, etc. ] 100) this integer is no longer in the array . do i need to use .push a splice

sorry I’m super confused by these questions.

Is there any reason you’re not interested in fixing your code as I’ve suggested above?

this was the code you showed us:

and as I said, you need to use an if-else statement (not 2 if statements) to get this to work.
Have you at least tried this?
If yes, please show the new code.

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";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}


function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(studentScore)) { 
  return ("class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + ".you passed the course"
} 
else { 
  return ( "class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + ".you failed the course" 
} 
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

Hi there!

You have missing the if statement condition and one of it’s body bracket. Also you have spacing, latter casing and quote marks issues within the returning strings.

I would reset the Challenge step because you have modified also your other code as well.

Remove the first parenthesis in your return statements as they are mismatched and do not do anything useful.

Then fix your returned string to be an EXACT match to the one requested by the step. (You can look at the console to see where you missed this from the spacing to the punctuation and the missing capital letters etc)

I’ve edited your code for readability. 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 (').

what is the if statement condition and also try to add space and capital letter at the first letter

please make your own post if you have a question about your code. (you can use the Help button in the step to help you open a post)

I am still not seeing what I’m missing here.

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(studentScore)) {
return "class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + “.you passed the course”
}
else {
return ( "Class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + “.you failed the course”
}
{

function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(studentScore)) {
return "Class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + “.you passed the course”;
} else {
return ( "Class average: " + getAverage(totalScores) + ".yourGrade: " + getGrade(studentScore) + “.you failed the course”
}
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));