Emperor
December 16, 2024, 2:37pm
1
Tell us what’s happening:
I have an error on the studentScore , its telling me that it is nit defined and i have tried many ways but still having errors
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) {
// User Editable Region
return "D";
} else {
return "F";
}
}
function hasPassingGrade(score) {
return getGrade(score) !== "F";
}
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 failed the course."
}
}
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));
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/131.0.0.0 Safari/537.36
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 4
Hi there!
The returning strings words Average
and Grade
should start with lowercase.
ILM
December 16, 2024, 3:10pm
3
here it’s not defined, if you want to test this value move this line to inside studentMsg
, or just delete it
Emperor
December 16, 2024, 3:16pm
4
It’s still not working i dunno what the issue is
You have only need to correct the returning strings as requested within the challenge instructions.
Correct code output:
Class average: 71.7. Your grade: F. You failed the course.
Your’s code output:
Class Average: 71.7 Your Grade: F You failed the course.
Check the difference.
Emperor
December 17, 2024, 1:12am
7
This is my code now
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) + " Your Grade: " + getGrade(studentScore) + " You passed the course.")
} else {
return ("Class Average: " + getAverage(totalScores) + " Your Grade: " + getGrade(studentScore) + " You failed the course.")
}
}
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));
console.log(hasPassingGrade(studentScore));
koyotem
December 17, 2024, 3:35am
8
I see you in your studentMsg function you use totalScores and studentScore as arguments, but I’m not seeing them defined as a variable or function anywhere else in your code before that.
Emperor
December 17, 2024, 3:55am
9
Yh so please any solution cause my head is on fire
koyotem
December 17, 2024, 4:54am
10
Ah actually you still need to change the uppercase “A” and “G” in your return lines to lowercase. They should look like the one here,
code removed by moderator
Emperor:
return (“Class Average: " + getAverage(totalScores) + " Your Grade: " + getGrade(studentScore) + " You passed the course.”)
} else {
return (“Class Average: " + getAverage(totalScores) + " Your Grade: " + getGrade(studentScore) + " You failed the course.”)
Your returning strings output in the console should match exactly:
Class average: 71.7. Your grade: F. You failed the course.
You need to correct the latter casing and need to add missing dots .
in the returning strings.
ILM
December 17, 2024, 9:53am
12
hi @koyotem
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
koyotem
December 18, 2024, 5:12am
13
Thank you for the feedback, I just started being active on the forum, my apologies.
Emperor
December 19, 2024, 1:47pm
14
I can’t see what you mean ,
ILM
December 19, 2024, 2:20pm
15
Emperor:
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(hasPassingGrade(studentScore));
you must remove studentScore
here, or things will not work. studentScore
doesn’t exist outside of studentMsg
, and your code and the tests stop working. If you don’t do this nothing else matters.
After that
let’s do some debugging:
Your function call of studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)
should return the following message: "Class average: 71.7. Your grade: F. You failed the course."
.
So let’s compare:
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log("Class average: 71.7. Your grade: F. You failed the course.");
this prints to the console:
Class Average: 71.7 Your Grade: F You failed the course.
Class average: 71.7. Your grade: F. You failed the course.
Your code has some errors, the string needs to match exactly
system
Closed
June 20, 2025, 2:20am
16
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.