Tell us what’s happening:
I need help with Javascript question , as I am working on building a gradebook app
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 classAverage = getAverage (totalScores)
const studentGrade = getGrade(studentScores)
const passed = hasPassingGrade(studentScore)
let message = 'Class average:${classAverage}. Your grade ${studentGrade}.'
if(passed) {
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));
// 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
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 4
Is this line giving an error in the console?
There shouldn’t be a space between the function name and the parentheses
Also have you tried to log this?
Does it work as you thought it would?
(String literals use backticks not quotes)
function studentMsg(totalScores, studentScore) {
const classAverage = getAverage(totalScores)
const studentGrade = getGrade(studentScore)
const passed = hasPassingGrade(studentScore)
let message = `Class average:${classAverage}. Your grade ${studentGrade}.`
if(passed) {
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));
I fixed the errors you pointed out and it still says it’s incorrect
Is this the correct spacing?
Also do you have the correct spacing for the end of the string?
let message = `Class average: ${classAverage}. Your grade ${studentGrade}.`
I think this is good spacing, but it still says error
You still have a missing space. You should log the final string and compare it with the one they wanted.
Edit: you are also missing a period
Yes, put the string they asked for next to the string you are logging and compare them.
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("Class average: 71.7. Your grade: F. You failed the course.")
This one still has an error
hbar1st
11
You seem to have two missing spaces.
Have you tried comparing the logged string to the one they gave?
Put them next to each other (one above and one below) so you can see the differences easier
for clarification, is the logged string the console.log (studentMSG)?
hbar1st
13
Yes when you log the call to studentMsg, you are logging the returned string
ok, so under that console log, I should put the class average?
hbar1st
15
Right here. What do these two give in the console pane? Copy the results in your next response.
It says that I need to return the following message, so do I need to put “return”?
hbar1st
18
You already have return. The problem is the missing spaces.
missing spaces?
Sorry, I’m new to javascript, can you please clarify?
nevermind, I think I figured it out
1 Like
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));
Fixed the spaces but still not working