Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Theres 2 things happening here that I cant seem to figure out.
First, the A++ array isnt even showing up until the “sorry your code does not pass” error pops up so im copying pasting it from there to console.log (not sure if there is a bug in this lesson.

Second, I cant figure out the last part on what Im doing wrong. Theyre either both passing or both failing.

// console output
Class average: 50.8. Your grade: A++. You passed the course.
Class average: 71.7. Your grade: F. You passed the course.

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) {
  if (getGrade) {
return "Class average: " + getAverage(totalScores) + "." + " Your grade: " + getGrade(studentScore) + "." + " You passed the course."
  } else {
    return "Class average: " + getAverage(totalScores) + "." + " Your grade: " + getGrade(studentScore) + "." + " You failed the course."
  }
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Look closely at your logic here.

Yes I also tried getGrade(score) but then it says that score is not defined. im stuck

How is getGrade() letting you know if the student passed or not?

well it has the if /else with operators but I dont understand how to translate it to passing or failing onto the string. ive been stuck here for 3 days :frowning:

What functions do you have available to use that might help you correct your logic there?

if score is not defined, use the variable that is available inside studentMsg instead, what variables do you have there?

Hi, ive tried using studentScore which is the 2nd parameter in studentMsg and it gives me the same error, that it isn’t defined. such as if i were doing:
if (getGrade(studentScore)) {} instead of just if (getGrade) {}

oh theres one called hasPassingGrade at the bottom but im unsure how to use it. Ive plugged it in and it doesnt do anything.. ive also returned it as well within the studentMsg function

Yes. That’s the one you need. It takes a score parameter, so pass in the student’s score when you call it there.

and what is returned by getGrade? it looks like you expect a boolean, but it isn’t that (note you have a different function that returns a boolean)

can you show that code?

thanks but i just tried that and im getting the same error; this time instead with both failing :frowning:

// console output
Class average: 50.8. Your grade: A++. You failed the course.
Class average: 71.7. Your grade: F. You failed the course.

code: function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(37)) {
return “Class average: " + getAverage(totalScores) + “.” + " Your grade: " + getGrade(studentScore) + “.” + " You passed the course.”
} else {
return “Class average: " + getAverage(totalScores) + “.” + " Your grade: " + getGrade(studentScore) + “.” + " You failed the course.”
}
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

You are hard-coding the student’s score rather than using the parameter that was passed in to the studentMsg() function.

1 Like

do all students have the same grade? why 37?

heres the output i get with (getGrade)
// console output
Class average: 50.8. Your grade: A++. You passed the course.
Class average: 71.7. Your grade: F. You passed the course.

my code:
function studentMsg(totalScores, studentScore) {
if (getGrade) {
return “Class average: " + getAverage(totalScores) + “.” + " Your grade: " + getGrade(studentScore) + “.” + " You passed the course.”
} else {
return “Class average: " + getAverage(totalScores) + “.” + " Your grade: " + getGrade(studentScore) + “.” + " You failed the course.”
}
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

aren’t you using hasPassingGrade now? why this code?

1 Like

The purpose of getGrade() is just to get the letter grade associated with the score. That’s all it does. It does not tell you if the student’s score is a passing or failing score.

You were so close when you used the correct function. You just needed to use the score parameter passed in to studentMsg().

1 Like

thank you so much!! this was it :smiley: man i was breaking my head here on this one. I really appreciate all your help! – when you told me i was hrd coding it, i didnt realize i was doing that at that point

thank you for your help! Its been solved :slight_smile: :grinning_face:

code removed by moderator

here is my code finally it pass