Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

please assist, my code is not returning the required message from the studentMsg() function… this is my code so far: function getAverage(scores) {
// Calculate the sum of all scores
const sum = scores.reduce((acc, score) => acc + score, 0);

// Return the average by dividing the sum by the number of scores
return sum / scores.length;
}

function getGrade(score) {
// Return the grade based on score thresholds
if (score === 100) {
return “A++”;
} else if (score >= 90) {

Your code so far


// User Editable Region

function getAverage(scores) {
  // Calculate the sum of all scores
  const sum = scores.reduce((acc, score) => acc + score, 0);

  // Return the average by dividing the sum by the number of scores
  return sum / scores.length;
}

function getGrade(score) {
  // Return the grade based on score thresholds
  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) {
  // Check if the grade is anything other than "F"
  return getGrade(score) !== "F";
}

function studentMsg(totalScores, studentScore) {
  // Step 1: Calculate the class average using getAverage
  const classAverage = getAverage(totalScores).toFixed(1); // Keep one decimal place for the output

  // Step 2: Determine the student's grade using getGrade
  const studentGrade = getGrade(studentScore);

  // Step 3: Determine if the student passed or failed using hasPassingGrade
  const passed = hasPassingGrade(studentScore) ? "passed" : "failed";

  // Step 4: Construct the message using string concatenation
  return "Class average: " + classAverage +
         ". Your grade: " + studentGrade +
         ". You " + passed + " the course.";
}

// Test cases
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)); 
// Expected: "Class average: 71.7. Your grade: F. You failed the course."

console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)); 
// Expected: "Class average: 50.8. Your grade: A++. You passed the course."


// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

I like the way you stepped through that!

Try removing toFixed() since that was not asked.