Instructions:
Complete the studentMsg function with totalScores and studentScore for parameters. The function should return a string representing a message to the student.
If the student passed the course, the string should follow this format: Class average: average-goes-here. Your grade: grade-goes-here. You passed the course.
If the student failed the course, the string should follow this format: Class average: average-goes-here. Your grade: grade-goes-here. You failed the course.
Use the getAverage function to get the class average.
Use the getGrade function to get the student’s grade.
Use string concatenation (+) to build the message.
Be careful with the punctuation and spaces in the message.
Now you need to use the format given in the instructions as returning string in if else statement. Read the instructions carefully and try again.
you are not answering my question. You just copy pasted the instruction in this step. I don’t know how to start because there are a lot of numbers which is confusing.
why isn’t my second if working? I have tried adding else and if … else but it’s not working
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) {
if (hasPassingGrade(totalScores)) {
return "Class average: 71.7. Your grade: . You passed the course."
} else {
return "Class average: 71.7. Your grade: F. You failed the course."
}
if (haspassingGrade(studentScore)) {
return "Class average: 50.8. Your grade: A++ . You passed the course."
}
}
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/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 not using the function’s for average and garde. Instead you have added simple text 71.7 and F.
Concatenate the function’s getAverage() and getGrade() within the string for class average and student grade. Use the parameters totalScores and studentScore as an argument.
It’s strange because I see some people using getAverage(totalScore) but there isn’t a function with that name. How come they just change the name of a function.
also, if the first function I created called.getAverage(scores) gives me the Class average score how come I can’t just use that function name to bring those numbers into a new function.
look at the functions. the getAverage() function have the calculation of average. getGrade() function have the calculation of grade. hasPasingGrade() function have the calculation of passing grade. if you call that funnctions in exact place with exact parmaters as an argument within the srings and concatenate it exactly it is needed, your challenge will pass.
you can not use the score as an argument. because you did not have score as a paramater within the function studentMsg(totalScores, studentScore) . you must use the paramters that you have within the function. also you have deleted some text in the beginning of your return strings.