Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

I can’t figure out where I’m going wrong:

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

### Your code so far


```javascript
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 avg = getAverage(totalScores);
  let grd = getGrade(studentScore);
  let msg = "";
  if (grd === "F") {
    msg = "Class average: " + avg + ". Your grade:" + grd + ". You failed the course.";
  } else {
    msg = "Class average: " + avg + ". Your grade:" + grd + ". You passed the course.";
  }
  return msg;
}
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/131.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Hi there!

Required output msg:

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

Your console output msg:

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

Carefully read the above two line and see the difference.
Hint: a white space is missing after Your grade:

So, quick follow up question: Is that about the validity of my code or just a “consequence” of freeCodeCamp’s “lesson-checking bot”?

I suppose my real question is “would my code have worked if placed in a real-world environment or did it fail simply because of the error as noted on freeCodeCamp?”

Thanks!

it depends. does your real world environment expect a string exactly like that? or something similar is good enough?

this is not html where spaces are less important, if you remove a space from a string it is a different string

1 Like