Build a Gradebook App - Build a Gradebook App

Tell us what’s happening:

  1. Your studentMsg function should return the correct message based on the student’s score and the class average. still wrong

Your code so far

function getAverage(scores) {
  let total = 0;
  for (let i = 0; i < scores.length; i++) {
    total += scores[i];
  }
  return total / scores.length;
}

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) {
  const grade = getGrade(score);
  return grade !== "F";
}

function studentMsg(scores, studentScore) {
  const avg = getAverage(scores);
  const avgFixed = Number(avg.toFixed(1)); // ensures correct number formatting
  const grade = getGrade(studentScore);
  const passed = hasPassingGrade(studentScore);
  const result = passed ? "You passed the course." : "You failed the course.";
  return "Class average: " + avgFixed.toFixed(1) + ". Your grade: " + grade + ". " + result;
}

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

Challenge Information:

Build a Gradebook App - Build a Gradebook App

hello and welcome back :slight_smile:

  • why not use “string literals”? that way string manipulation gets much easier
  • also console out your return statement and see if that seems right to you

happy coding :slight_smile:

are you sure this is a thing to do?