Tell us what’s happening:
Im not sure what I’m doing wrong I’ve been trying for a while and in need of help
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) {
const averageScore = getAverage(totalScores);
const grade = getGrade(studentScore);
let message = `Class average: ${averageScore}. Your grade: ${grade}.`;
if (grade >= 50) {
message += " You failed the course.";
} else {
message += " You passed the course.";
}
return message;
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
// 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/18.4 Safari/605.1.15
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 4
ILM
April 28, 2025, 2:30pm
2
are you sure on the condition for passing or failing?
I still get the average and the message looks correct but its only returning the else message.
ILM
April 28, 2025, 3:46pm
4
double check the condition, you are checking grade
, where does that come from?
the grade comes from the average but It still logs incorrect
ILM
April 28, 2025, 4:13pm
6
that doesn’t look like what’s written in your code
what does getGrade
do?
its pulling the getGrade function to have all the student scores
ILM
April 28, 2025, 4:36pm
8
that doesn’t seem a correct explanation, you can look above to see what the getGrade
function does
the getGrade function it returns the grades from A to F so all the scores can have its own set of grades
ILM
April 28, 2025, 5:20pm
10
so does it make sense to compare a letter with 50
?
I’ve tried a new condition but its still failing.. How do I put my updated code?
ILM
April 28, 2025, 6:06pm
12
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 (').
function studentMsg(totalScores, studentScore) {
const averageScore = getAverage(totalScores);
const grade = getGrade(studentScore);
let message = `Class average: ${averageScore}. Your grade: ${grade}.`;
if (getGrade !== "F") {
message += " You failed the course.";
} else {
message += " You passed the course.";
}
return message;
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
Still seems to be an error but still trying to figure it out
ohhh its suppose to be grade! im trying to call the getGrade function to pass in my studentScore to return the letter grade in my variable.
function studentMsg(totalScores, studentScore) {
const averageScore = getAverage(totalScores);
const grade = getGrade(studentScore);
let message = `Your average: ${averageScore}. Your grade: ${grade}.`
if (grade !== "F") {
message += " You passed the course."
} else {
message += " You failed the course.";
}
return message;
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));```
ILM
April 28, 2025, 10:19pm
16
now make sure the message you are returning is the one that is in the requirements
its definitely logging correctly now but it still says its incorrect
ILM
April 28, 2025, 10:28pm
18
in the last code you posted you have the wrong message
just figured out thanks for the guidance!
The grade is ‘F’ cos the studentScore is 37