Review Javascript Fundamentals by Building a Gradebook App - Step 4

Hi, I have this code for the exercise and the output is correct and the spacing and punctuation looks correct, but its still giving an error.

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) {

let a = getAverage(totalScores);
let b = getGrade(studentScore);

if (b !== 'F'){
  return ("Class Average: "+ a + ". Your Grade: " + b + ". You passed the course.");
}
else {
  return ("Class Average: "+ a + ". Your Grade: " + b + ". You failed the course.");
}
}

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

Output is this

// running tests
Your function call of studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37) should return the following message: "Class average: 71.7. Your grade: F. You failed the course.".
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.".
Your studentMsg function should return the correct message based on the student's score and the class average.
// tests completed
// console output
Class Average: 71.7. Your Grade: F. You failed the course.
Class Average: 50.8. Your Grade: A++. You passed the course.

Hi and welcome to the forum.
Please note:

1- you should use the function hasPassingGrade instead of redoing the work in your new students function

2- the string returned has to match —exactly— even in terms of case (capital letters ) and spacing.

Hi there and welcome to our community!

Expected output:

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

Your output:

"Class Average: 71.7. Your Grade: F. You failed the course."

Can you see where the differences are? Your code works but you haven’t exactly matched the required output string.

Thanks so much, the capitalization was the issue.

1 Like

As @hbar1st says though, although your code now passes, you should be using the hasPassingGrade function too.