Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Error, why 71.7 is F and 50.8 is A++. I think there is some errors here.

Your code so far

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";
}


// User Editable Region

function studentMsg(totalScores, studentScore) {
  let average = getAverage(totalScores);
  let grade = getGrade(average);
  let pass = hasPassingGrade(average);
  let notice = "";
  if (pass) {
    notice += "passed";
  } else {
    notice += "failed";
  }
 
  return "Class average: " + average + ". Your grade: " + grade + ". You "+ notice + " the course.";
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Hi there and welcome to our community!

Your issue is that you’re calculating a student’s grade and pass/fail on the average of all students’ scores. You should be calculating this on the individual student’s score, using the studentScore parameter in your function.

hey good day everyone! can you help me with this one I got stuck with it and I dont know what to do!
here is my code:

unction studentMsg(totalScores, studentScore) {
let passFail
if (hasPassingGrade(studentScore)){
  passFail=" You Passed the course."
}else {
  passFail=" You failed the course."
}
return "Class average: " + getAverage(totalScores) + ". Your grade: " + getGrade(studentScore) + "." + passFail;
}


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

hey @jakeheroala

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like