Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

I have tried for at least 1 hour and I still can’t get it right , may I get a hint or can you guys tell me what’s wrong with my code please? Step 4 btw

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) {
let average = getAverage;
let grade = getGrade;
if (grade === "F" ) {
  return "Class average:" + average + "Your grade:" + grade

}
else {return "Class average:" + average + "Your grade:" + grade }
}
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/126.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

To call those functions, you’ll need to include the parentheses and pass an argument for each function to work with.

Also, check the string you’re returning in the studentMsg function.
Try adding this below your existing console.log() for comparison:

// expected output
console.log("Class average: 71.7. Your grade: F. You failed the course.")

When I put parentheses at the function calls it says this “TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))” and if I try to pass an argument it says " x is not defined".

And for the string I am returning , I don’t really understand I am supposed to check…

Hi there!
Post your update code.

Here it is.

function studentMsg(totalScores, studentScore) {

let average = getAverage();

let grade = getGrade();

if (grade === "F" ) {

return "Class average:" + average + "Your grade:" + grade

}

else {return "Class average:" + average + "Your grade:" + grade }

}

console.log("Class average: 71.7. Your grade: F. You failed the course.");

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Look at the console. Are you getting the exact message they asked for?

As I said, you will need to pass an argument to these functions, otherwise they will return an error as they have no data to work with. When you call getAverage(), for instance, what are you trying to get the average of?

Also for the If condition, check hasPassingGrade function.