Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

I have followed all instructions to complete the studentMsg function.What is wrong?

Your code so far

if (studentScore>=60){return "Class average:71.7.Your grade: grade-goes-here.You passed the course."}
else if (studentScore<60){return "Class average:average-goes-here.Your grade: grade-goes-here.You failed the course."}

}


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

console.log(studentMsg(37));



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 Edg/131.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

You are not returning the correct string.

You have to use both function parameters and the functions already in the code used to check for a passing grade, getting the average, and getting the grade.

Params:
totalScores
studentScore

Functions:
hasPassingGrade
getAverage
getGrade

What about this?

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) {
const classAverage=getAverage(totalScores);
const studentGrade=getGrade(studentScore);
const passed=hasPassingGrade(studentScore)

if(passed){return 'Class average:${classAverage}. Your grade: ${studentGrade}.You passed the course.'
}
else {return 'Class average: ${classAverage}.Your grade: ${studentGrade}.You failed the course'}
}


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






Hi @zm17jaga

The expected output is:

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

The output of your function:

Class average: ${classAverage}.Your grade: ${studentGrade}.You failed the course

Hi there!

You are using quote marks around the returning strings. You actually need to use template literals string ()` , a back tick. Also make sure the spacing and punctuation within the string are correct.

1 Like

As said, you need to use backticks for the template strings.

But your return strings also have to match the expected strings exactly, that include all the correct spaces and punctuation.