Tell us what’s happening:
My code is working (I think) but the results are all showing up as true. Can you help me?
Your code so far
function getAverage(scores) {
let sum = 0;
for (const score of scores) {
sum += score;
}
return sum / scores.length;
}
function getGrade(mark) {
if (mark === 100) {
return "A++";
} else if (mark >= 90) {
return "A";
} else if (mark >= 80) {
return "B";
} else if (mark >= 70) {
return "C";
} else if (mark >= 60) {
return "D";
} else {
return "F";
}
}
// User Editable Region
function hasPassingGrade(testScore) {
getGrade();
if (testScore == "F") {
return false;
} else if () {
return true;
}
}
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/127.0.0.0 Safari/537.36 Edg/127.0.0.0
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 3
Hi,
So you need to know some things which will make it clear for you.
Your getGrade needs to take a value ( the score for example) and then return F or D… based on that score. Then you need to store whatever is returned from getGrade in a variable. And finally, use that variable inside your if statements to check if it is an F or D or… Also you don’t need an extra if ()
after your else
so remove that.
Hope this helps!
I tried that but now they’re all showing up as false.
Ok, can you share your new code?
Sure! Here it is:
function hasPassingGrade() {
let testScore = getGrade();
if (testScore == “F”) {
return false;
} else {
return true;
}
}
console.log(hasPassingGrade(100));
console.log(hasPassingGrade(53));
console.log(hasPassingGrade(87));
Ok, you are almost there.
As you can see above, you have passed 100 to this function as a parameter.
So when you define the function hasPassingGrade, make sure to add a parameter to it (right now it doesn’t have a parameter so how can it receive the score?).
ex: function checker ( count ){ }
. here count is a parameter.
Whatever your parameter is named, you will pass it to the getGrade function and it’s done. What it means is your hasPassingGrade takes an argument, passes it to getGrade and getGrade will return you the grade, then you use your statements with that grade. Hope this is clear.
I tried that but it did nothing.
BTW here is my new code:
function hasPassingGrade( count ) {
count = getGrade();
if (count == “F”) {
return false;
} else {
return true;
}
}
console.log(hasPassingGrade(100));
console.log(hasPassingGrade(53));
console.log(hasPassingGrade(87));
Your testScore variable was okay, you didn’t have to replace that. bring it back. Then pass count inside the getGrade as a parameter.
1 Like
I tried it and it finally worked. Thanks so much!
1 Like
I’m glad it worked for you. You just have to understand the logic behind the functions in such steps. Good luck!