Review js fundamentals by building a gradebook app - Step 4

Help me understand where I’m going wrong, please

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 studentMsg(totalScores, studentScore) {
  // Calculate the class average using the getAverage function
  let average = getAverage(totalScores);

  // Determine the student's grade using the getGrade function
  let grade = getGrade(studentScore);

  // Determine if the student passed or failed
  let passed = grade !== "F";

  // Construct the message based on pass or fail status
  if (passed) {
    return `Class average: ${average.toFixed(2)}. Your grade: ${grade}. You passed the course.`;
  } else {
    return `Class average: ${average.toFixed(2)}. Your grade: ${grade}. You failed the course.`;
  }
}

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

don not round the value. remove that from your both returning values…

1 Like

I removed it and it presented another error that it didn’t have before

if (passed) {
  return `Class average: ${average}. Your grade: ${grade}. You passed the course.`;
} else {
  return `Class average: ${average}. Your grade: ${grade}. You failed the course.`;
}

image

because this is not determine if the student is failed, it is only determine student passed.

I can’t get through the stage

post the link to that challenge step.

post your full code again please

it might fail because the test has asked to use concatenation rather than template literals

1 Like

I used template literals and passed the test. at first i thought i failed because of it. I checked the instructions again and changed the console.log to return statement and kept the template literals and passed it.

4 Likes

was wondering where I went wrong😅, tysm

initialize the grade variable to the function then return this line “A passing grade is anything that is not an “F””.

You do’t need console.log anymore, you have to call it, I struggled for an hour on this!