Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

Hey this 22 part is not working

function getAverage(scores) {
  const total = scores.reduce((sum, score) => sum + score, 0);
  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, studentScore) {

Your code so far

function getAverage(scores) {
  const total = scores.reduce((sum, score) => sum + score, 0);
  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, studentScore) {
  const average = getAverage(scores).toFixed(1); // Force 1 decimal in string
  const grade = getGrade(studentScore);
  const passed = hasPassingGrade(studentScore) ? "passed" : "failed";
  return `Class average: ${average}. Your grade: ${grade}. 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

Challenge Information:

Build a Gradebook App - Build a Gradebook App

In what way is your code not working? What have you tried to debug your code?

the 22th part is showing that " 22. Your

studentMsg

function should return the correct message based on the student’s score and the class average."

Ok. What have you tried to debug your code though?

Sorry I debugged the code by tracing each function step-by-step:

  • First , I checked the getAverage() function by logging its output with sample arrays to confirm it was calculating and rounding correctly.
  • Next , I tested the getGrade() function using a range of scores (e.g., 59, 60, 70, 90, 100) to verify the correct grade boundaries.
  • Then , I used console.log() in the studentMsg() function to inspect the average, grade, and pass/fail status.
  • Finally, I noticed a redundancy in formatting: getAverage() already returns a number rounded to 1 decimal, and I was calling .toFixed(1) again in studentMsg() , which converts it back to a string — so I cleaned that up.

Wait, where did the instructions tell you to round? Where did you get that piece?

Dont we need to change that decimal position into fixed value

Please point to where you think the instructions said that. I cannot find that instruction.

return Number((total / scores.length).toFixed(1));

That is in the INSTRUCTIONS? I do not see that code in the INSTRUCTIONS?

the instruction didn’t told that but i have done myself isn’t that right

If the instructions did not ask you to do that, then you probably should not do it.

// 1. Function to calculate the average of scores
function getAverage(scores) {
  const total = scores.reduce((sum, score) => sum + score, 0);
  return Number((total / scores.length).toFixed(1)); // Rounded to 1 decimal place
}

// 2. Function to determine letter grade from score
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";
}

// 3. Function to check if score is passing (not "F")
function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}

// 4. Function to generate student message
function studentMsg(scores, studentScore) {
  const average = getAverage(scores);
  const grade = getGrade(studentScore);
  const passed = hasPassingGrade(studentScore) ? "passed" : "failed";
  return `Class average: ${average}. Your grade: ${grade}. You ${passed} the course.`;
}

Is this code is not correct then

I don’t know why you re-posted 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 (').

function getAverage(scores) {
  const total = scores.reduce((sum, score) => sum + score, 0);
  return total / scores.length;
}

is this good then

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 could try that code and see?

is that three backtick there

Yes it went correct. Thank you for your help