Tell us what’s happening:
Okay I have tried multiple things for this issue that I am having. I am 99% it’s my “If” statement. “studentScore” is not defined in the code you see now but I have console.logged and defined it separately it and it only displays “true” or “false”, what I want it to do is, “if true, return the message I put together” but it ain’t doing anything defined or not.
Would like some tips on what is wrong with my condition or maybe my argument. Please let me know!
Thank you 
Your code so far
function getAverage(scores) {
let sum = 0;
for (const score of scores) {
sum += score;
}
return sum / scores.length;
} //Gets the average *Above* //
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";
}
}
// Checks scores with the conditions to see if they had passed *Above* //
function hasPassingGrade(score) {
return getGrade(score) !== "F";
}
// To check if they did not pass *Above* //
// User Editable Region
function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(studentScore)) {
return "Class Average: " + getAverage(totalScores) + " Your Grade: " + getGrade(studentScore) + " You passed the course."
} else {
return "Class Average: " + getAverage(totalScores) + " Your Grade: " + getGrade(studentScore) + " You did not pass the course."
}
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log(hasPassingGrade(studentScore))
// 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/126.0.0.0 Safari/537.36
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 4
you are calling hasPassingGrade with studentScore outside the studentMsg function, where studentScore is not defined
so I am not even in the “{ }” brackets?
I have been coding for 6hrs on this 5 step lesson ahahaha I love it.
1 Like
But it shows I am within the brackets? Am I actually not seeing it correctly?
see your code shows this here
correct approach will be
I actually think I am looking at two identical images right there, I really can’t see the difference…
I think I am going insane.
see near if sentence you will notice the indentation
I still can’t… it’s 4 am, I am gonna go to bed and try looking in the morning.
Thank you for you time and help though!
I will return tomorrow.
ok sleep well good night.
Hi again.
To me it looks like the strings you are returning are missing some periods in the middle. To check, just assign the strings you are making to a variable then log it before returning it.
Hi there,
The OP is asking about JavaScript code. The indentation inside the parentheses does not affect how the js code is running, it only affects the readability of the code.
Good morning, I am back again and I don’t get what you mean by the periods that I am missing. I have now added the string variables still showing the same thing.
I now have tried to have it all in a variable to then return the outcome but it tells me it is not defined, I don’t think I understand how I define the arguments to then output what I am trying to do.
Also is this a better approach for now or shall I return to the way I had it before?:
Screenshots are not a good way to share your code here.
I’m not sure why you changed the logic. In my last response I was suggesting a way for you to log the message before you return it. That way you can see the missing periods (dots).
Sorry about that. So I have now reverted the way I had it originally but have kept my string variables and have console.logged my strings and they are not defined. I don’t know what I am missing or where I need my periods to go. I am just confused right now.
"you did not pass the course."
where did you get that?
the instructions gave you a diffrent sentence.
1 Like
I have changed that, I missed that sorry.
Thank you.
It was outside the local scope, my bad. I see when I even just try to pass it it shows (studentMsg) has a whole different array then I can even see here, my question is where would I even get this array length of numbers and such?
I didn’t know I was even meant to do that but it’s like cheating because I can see what I need for it to work but what I want to do is get it without just copy and pasting it in as the argument.
can you share your most recent code here?
So I finally seen my issue with the periods I was missing. I just added them themselves.
But how was I meant to know this console.log? I see my code is now defined but I did not have this info before?
(line 46)
I will answer your question but please, when you are asked to share your code, please, copy the code into the forum instead of taking a screenshot. Screenshots are useful in cases when you want to show something on the screen but not for sharing code.
When you started this step, you were shown the following code in the editor:
function studentMsg(totalScores, studentScore) {
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
This code gave you a skeleton of the studentMsg function. It showed also that studentMsg expects 2 parameters. The console.log at the end showed you an example of how the studentMsg will be called (with an array of scores and one student’s score).
Whenever you see something like this again, you can ignore the console.log statement or change it to help you debug. The important bit is the code that you write in the function as that is what will determine whether the tests pass or fail.
3 Likes