Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

The function works properly, but it only shows one result as:

Class average: 71.7. Your grade: F. You failed the course.

While the lesson asked me to return another following:

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.".


I tried to reset the lessons but to no avail. I’m missing something.

Any suggestions or advices are greatly appreciated.
Thanks in advance!

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(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));

// 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

Hello again!

You have two plus signs here. You only need one.

1 Like

Hi again!

I cant believe that was it lol. Thanks as always!

1 Like

Welcome! May I suggest to you that you also try checking the console as you code in order to catch any obvious issues there.

And you should start thinking about using indentation when you code. You can read about coding style below. Part of learning to code properly is writing code in a way that is readable by others and trying to learn early will help you when you get to the projects.

https://standardjs.com/rules.html

1 Like