Building a Gradebook App -

My codes are not passing to complete the last step of the project.
The notice alert: Your

studentMsg

function should return the correct message based on the student’s score and the class average.
________________________>>>>>>
The codes are thus:

 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";
}

function studentMsg(totalScores, studentScore) {

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

Please post a link to the project. Also, please talk about how you got stuck trying to figure out how to fix your code.

I’ve edited your post to improve the readability of the code. 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 (').

You need to implement the studentMsg function.

please how can i do that?

We cannot write that code for you. You need to try it yourself. If you have specific questions about what the instructions are asking, you can ask them here.

Use the functions you’ve already built with the parameters passed to studentMsg. Check the instructions again for what the message should look like.

1 Like

i have followed through and this is what i came up with

//

function studentMsg(totalScores, studentScore) { 
  let average = getAverage(totalScores);
  let grade = getGrade(studentScore);
  let status = grade === "F" ? "failed" : "passed";
  return "Class average: " + average.toFixed(1) + ". Your grade: " + grade + ". You " + status + " the course.";
}

console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

// this is what is on the console after that;

// running tests 3. Your

studentMsg

function should return the correct message based on the student’s score and the class average. // tests completed // console output Class average: 50.8. Your grade: A++. You passed the course. Class average: 71.7. Your grade: F. You failed the course.

Nicely done! But note that the instructions did not ask you to format the average.

I’ve edited your post to improve the readability of the code. 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 (').

Really helpful, I have passed!