I’d be happy to help you. I just cannot write the answer for you, so we have to work towards fixing the code.
The very first thing to try to fix this is to run the function and compare the output to what the instructions ask for. That’s really the only reliable way I know to find and fix an error like this.
I would take a break. Being frustrated sucks and you’ve been at this for a while. But I would come back to this. The majority of effort in coding is working through being stuck in situations exactly like this so it’s important to work through this sort of thing when learning.
The website really does not have feelings. It honestly is just checking your output against the instructions.
I would like to see you pass the step. I would take a break and come back to this later. Like I said, this is a big part of what programming is - working through being stuck.
Spent 3 hours on this one step which isn’t getting completed, Step 22 is so impossible to get correct, can someone provide me with the answer. I already gave up and almost stressed out from being stuck on this 1 step and it’s annoying me that I can’t get it correct so can someone help me and explain why I can’t get it correct
Your code so far
function getAverage(scores) {
let total = 0;
for (let score of scores) {
total += score;
}
return Number((total / scores.length).toFixed(1));
}
function getGrade(score) {
if (score === 100) return "A+";
if (score >= 90) return "A";
if (score >= 80) return "B";
if (score >= 70) return "C";
if (score >= 60) return "D";
return "F";
}
function hasPassingGrade(score) {
return getGrade(score) !== "F";
}
function studentMsg(scores, score) {
const avg = getAverage(scores); // already rounded and is a number
const grade = getGrade(score);
const passed = hasPassingGrade(score);
return `Class average: ${avg}. Your grade: ${grade}. You ${passed ? "passed" : "failed"} the course.`;
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
// Class average: 71.7. Your grade: F. You failed the course.
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
// Class average: 50.8. Your grade: A+. You passed the course.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36