Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

I have an error on the studentScore , its telling me that it is nit defined and i have tried many ways but still having errors

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

// User Editable Region

    return "D";
  } else {
    return "F";
  }
}

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}


function studentMsg(totalScores, studentScore) {
if (hasPassingGrade(studentScore)) { 

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([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));
console.log(hasPassingGrade(studentScore));


// 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/131.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Hi there!

The returning strings words Average and Grade should start with lowercase.

here it’s not defined, if you want to test this value move this line to inside studentMsg, or just delete it

It’s still not working i dunno what the issue is

what is your code now?

You have only need to correct the returning strings as requested within the challenge instructions.

Correct code output:

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

Your’s code output:

Class Average: 71.7 Your Grade: F You failed the course.

Check the difference.

This is my code now

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


function studentMsg(totalScores, studentScore) {
  
if (hasPassingGrade(studentScore)) { 

  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([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));
console.log(hasPassingGrade(studentScore));

I see you in your studentMsg function you use totalScores and studentScore as arguments, but I’m not seeing them defined as a variable or function anywhere else in your code before that.

Yh so please any solution cause my head is on fire

Ah actually you still need to change the uppercase “A” and “G” in your return lines to lowercase. They should look like the one here,

code removed by moderator

Your returning strings output in the console should match exactly:

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

You need to correct the latter casing and need to add missing dots . in the returning strings.

hi @koyotem

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for the feedback, I just started being active on the forum, my apologies.

I can’t see what you mean ,

you must remove studentScore here, or things will not work. studentScore doesn’t exist outside of studentMsg, and your code and the tests stop working. If you don’t do this nothing else matters.

After that

let’s do some debugging:

Your function call of studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37) should return the following message: "Class average: 71.7. Your grade: F. You failed the course." .

So let’s compare:

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

this prints to the console:

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

Your code has some errors, the string needs to match exactly