Review js fundamentals by building a gradebook app - Step 4

function studentMsg(totalScores, studentScore) {

let totalScores = getAverage(totalScores)

let studentScore = getGrade(studentScore)

if (studentScore != “F”) {

return "Class average: " + totalScores + ". Your grade: " + studentScore + “. You passed the course.”

} else if (studentScore == “F”) {

return "Class average: " + totalScores + ". Your grade: " + studentScore + “. You failed the course.”

};

}

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

It is showing error, can someone please explain why.

Hi there!

Post a link to the challenge step also.

You used different quote marks within the condition and returning strings. Keep the straight double quote " marks replace the curly ones with the straight double quote" mark.

And what is my problem?

function studentMsg(totalScores, studentScore) {
const average = getAverage(totalScores);
  const grade = getGrade(studentScore);

  // Check if student has passed or failed
  if (grade !== "F") {
    return "Class average: " + average.toFixed(1) + ". Your grade: " + grade + ". You passed the course.";
  } else {
    return "Class average: " + average.toFixed(1) + ". Your grade: " + grade + ". You failed the course.";
  }
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

–solution code removed

Hi there!

Your problem is toFixed() method. You didn’t need round the grade marks.
@MaryGothic

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.

They are all the same it was when i was copying it here that it changed

Post your code here within the pair of three back ticks (```). Back ticks should be on a separate line before and after your code. Also include link to the challenge step after your last three back ticks

function studentMsg(totalScores, studentScore) {

let totalScores = getAverage(totalScores)

let studentScore = getGrade(studentScore)

if (studentScore != “F”) {

return Class average: + totalScores + . Your grade: + studentScore + . You passed the course.

} else if (studentScore == “F”) {

return Class average: + totalScores + . Your grade: + studentScore + . You failed the course.

};

}

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

The console is throwing an error on above parameters initialization. It’s already been declared as the function () parameters above, so you didn’t need to use let keyword.

You need only else block after if block. And the condition is not required for else block. Also fix the spacing and punctuation within the returning strings also. The output should be exactly as the test required it. Then your code will pass.

I have done all that but still error.

Post your updated code here in your next reply. Add three back ticks or use </> preformatted text option in reply settings to insert back ticks automatically. Place your code between the back ticks. Back ticks should be on a separate line before and after your code.

Can u please help me This error is showing :
Your studentMsg function should return the correct message based on the student’s score and the class average.

function studentMsg(totalScores, studentScore) {
const average = getAverage(totalScores);
const grade = getGrade(studentScore);

if(grade !== “F”){
return "Class average: " + average.toFixed(1) + ". Your grade: " + grade + “. You passed the course.”;
}
else{
return "Class average: " + average.toFixed(1) + ". Your grade: " + grade + “. You failed the course.”;
}
}
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

You have already created your own topic for this issue, and I have answered you there.