Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Hello, I’ve been attempting to work on this code for a while but still don’t understand where I’ve gone wrong.

This is my code:

function studentMsg(totalScores, studentScore) {
  if (getAverage >= 60 || hasPassingGrade == true) {
    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));

This is the error I keep getting:

// running tests 
Your function call of studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100) should return the following message:
"Class average: 50.8. Your grade: A++. You passed the course.". 
Your studentMsg function should return the correct message based on the student's score and the class average. 
// tests completed 
// console output
Class average: 71.7. Your grade: F. You failed the course. 
Class average: 50.8. Your grade: A++. You failed the course.

Is there something wrong with my conditional statement? Please explain :cry: .

Couple of issues.

1- to call a function you just use parenthesis and give the function any arguments it expects.

2- what is your if statement trying to do? Try to think more about the logic needed.

1 Like

Hi there and welcome to our community!

This is the only line which is causing you problems:

Firstly, both getAverage and hasPassingGrade are functions so can only be useful in a conditional statement if you’re calling them with an argument (i.e. you should include the function parentheses and parameters).

Secondly, why are you including getAverage in this statement at all? The student has passed or failed based only on their individual score. If they have a passing grade you return the first string. If not, you return the second.

1 Like

Okay, I finally solved the problem. I just had to change the condition to mod edit: code removed
My bad. Thanks for the help ;).

Instead of comparing the grade to F, is there another function that does that already that you could have used?

2 Likes

hasPassingGrade. Thanks !

Great work! I edited a couple of your posts to hide your solutions while keeping the thread to help others. Just fyi.

1 Like

Sorry about that :p.

1 Like