Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

My code cannot pass the test case 17 and 22. I don’t know if the code has some error.

Your code so far

function getAverage(arrayOfTestScore) {
  let sum = 0;
  for (let each of arrayOfTestScore) {
    sum += each;
  }
  let average = sum / arrayOfTestScore.length;
  return Number(average.toFixed(1));
}

function getGrade(studentScore) {
  if (studentScore === 100) return "A+";
  if (studentScore >= 90) return "A";
  if (studentScore >= 80) return "B";
  if (studentScore >= 70) return "C";
  if (studentScore >= 60) return "D";
  return "F";
}

function hasPassingGrade(grade) {
  return grade !== "F";
}

function studentMsg(arrayOfScore, score) {
  const averageScore = getAverage(arrayOfScore).toFixed(1); // convert to string with 1 decimal
  const grade = getGrade(score);
  const passed = hasPassingGrade(grade);

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0

Challenge Information:

Build a Gradebook App - Build a Gradebook App

Welcome to the forum :wave:

Review user stories 3 and 4 and make sure they are implemented correctly

function getAverage(arrayOfTestScore) {
  let sum = 0;
  for (let each of arrayOfTestScore) {
    sum += each;
  }
  let average = sum / arrayOfTestScore.length;
  return average;
}

function getGrade(studentScore) {
  if (studentScore === 100) return "A+";
  if (studentScore >= 90) return "A";
  if (studentScore >= 80) return "B";
  if (studentScore >= 70) return "C";
  if (studentScore >= 60) return "D";
  return "F";
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}

function studentMsg(arrayOfScore, score) {
  const average = getAverage(arrayOfScore).toFixed(1);
  const grade = getGrade(score);
  const passed = hasPassingGrade(score);
  return `Class average: ${average}. Your grade: ${grade}. You ${passed ? "passed" : "failed"} the course.`;
}

I updated the code but it stills fails the test 22. Could you please help me with this.

if the scores are [33, 44, 55, 66, 77, 88, 99, 100], what average does your function print? the expected is 70.25

My function is printing 70.25 but I have formatted in the studentMsg function to give 1 decimal point. When I removed the toFixed method the code is accepted. Thank You so much for your time, really appreciate it.

1 Like