Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

I’m clearly not understanding something here. The instructions are to find the average score of the array. What am I doing wrong?

Your code so far


// User Editable Region

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

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 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

A ‘return’ statement immediately stops a function

I thought that was the point…

sumTotal = sumTotals + scores[i]
typo ?

I was overcomplicating things. Solved it. Thank you

1 Like

The point should not be to immediately stop the function inside of a loop unless you sometimes want the loop not to finish.