Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

I get Nan when trying to return in my function, I believe i got the loop to get the sum of all scores to be working

Your code so far


// User Editable Region

function getAverage(scores) {
  for (let i = 0; i < getAverage.length; i++) {
    scores += getAverage[i];
  };
  return scores /scores.lengt;
}

console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
console.log(getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]));

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

The for loop should iterate through the scores array to get the sum of all scores.

getAverage is the function you’re defining, not an array.

Also, typo:

function getAverage(scores) {
  let sum = 0
  for (let i = 0; i < getAverage.length; i++) {
    sum += scores[i];
  };
  return sum / scores.length;
}

console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
console.log(getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]));

I updated it but I am still not understanding, I have tried to go to the previous lesson but to no avail

There is still a problem with your for loop.

The purpose of this loop is going through the scores array to get the sum of all scores, right?

Take a look at the condition of your for loop:

i < getAverage.length

Does this make sense to you?

Thank you it makes sense