Review js fundamentals by building a gradebook app - Step 2

I’m not sure where I’ve made the mistake in my code , although the function is returning grades its also returning Undefined. Any help appreciated

function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}
// User Editable region

function getGrade(score) {
  if (score === 100){
    console.log("A++"); 
  } else if (score <= 99 && score >= 90){
    console.log("A");
  } else if (score <= 89 && score >= 80){
    console.log("B");
  } else if (score <= 79 && score >= 70){
    console.log("C");
  } else if (score <= 69 && score >= 60){
    console.log("D");
  } else {
    console.log("F");
  }
  return console.log(score)
}

console.log(getGrade(96));
console.log(getGrade(82));
console.log(getGrade(56));

// User editable region ends

you are trying to return the result of the logging statement.
Instead you should just return a variable which contains the grade.

(You will need to make one as you didn’t actually do that yet)

if (score === 100){
console.log(“A++”);
} instead of this you do
if (score === 100){
return “A++”;
}

hi there @csaisashank67 !

do not post working code as a solution. posting sloution code is not allowed here on the forum.

okk sir think some of people are posting so i also think to post to help some people

1 Like

alright, you can give solution by posting hints or suggestions.

1 Like