Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

I have found a solution for this exercise that generates the expected result as seen on the website CONSOLE. However it returns an error. Can anyone, please give me insight on this solution? Thank you in advance for your help.

Your code so far


// User Editable Region

function getAverage(scores) {
  let i=0;
  let sum=0;
  for(i=0;i<scores.length;i++){
       sum += scores[i];
       return;
  }
  console.log(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]));

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

do you see two undefined on the console? that’s what these print because it’s what your function returns. You need to return the value from your function, not print it.

also, the console.log here is never reached because the return executes first, it stops the function, but it doesn’t determine an output, so the output is undefined

1 Like

Thank you, I overlooked “return” is within the loop.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.