Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Tell us what’s happening:

I don’t know what to declare and where to declare it, I don’t know how to utilize the “getGrade” function, I have some idea on what to but I’m not sure if I did it right, can somebody break it down for me?

Your code so far

function getAverage(scores) {
  let sum = 0;

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

  return sum / scores.length;
}

// User Editable Region

let scoreRange = [100, 90 - 99, 80 - 89, 70 - 79, 60 - 69, 0 - 59];
function getGrade(score) {
  
  let grade;
  if (getGrade(score) >= 90) {
    grade = "A";
  }else if (getGrade(score) <= 99) {
    grade = "A";
  }
  if (getGrade(score) <= 89) {
    grade = "B";
  }else if (getGrade(score) >= 80) {
    grade = "B";
  }else {
    grade = "F";
  }
}
console.log(grade);
console.log(getGrade(96));
console.log(getGrade(82));
console.log(getGrade(56));

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

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 2

This variable is only defined inside of your function so you cannot use it outside of your function. You need to use the return keyword

It didn’t work brother, I declared the grade variable globally and used the return keyword and my code didn’t pass. Why?

I absolutely wouldn’t pollute the global space. What is the code with the return keyword?