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
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.
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
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.
{ } 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
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.
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.