Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

says the getAverage function should return a number, not sure why this is not working,

Your code so far


// User Editable Region

function getAverage(scores) {

for(let i = 0; i < scores.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]));

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

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

no return statement
your loop is also empty

and the return statement outside the function is also a syntax error

1 Like

Please consider indenting your code properly as it will help you find bugs like the one you have right now. Here’s the correct indentation:


function getAverage(scores) {

  for(let i = 0; i < scores.length; i++);
    sum += scores[i];
  }

  return sum/scores.length;

I pushed the code within the function 2 spaces to the right.
I also pushed the code within the for 2 more spaces to the right.

Now looking at this correctly indented code. Do you notice anything is missing?
(what should the last line of this function have? what about the for loop statement? It is also missing something important at the end of the line - the semicolon doesn’t belong there)

1 Like

I think you missed that the for loop is actually empty, there is a semicolon finishing the for loop, and there are no curly brackets for the for loop block

1 Like

i mentioned this in my post though?

1 Like

ok thanks so much. i figured it out

I put my code into vs code and console logged each line to find my errors. very frustrating until i realized what i left out