Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

i’m getting this error. not sure whats the problem
Sorry, your code does not pass. Hang in there.
Your getAverage function should return a number.

Your code so far


// User Editable Region

function getAverage(scores) {
  let lengthOfArray = scores.length;
  let totalOfAll= lengthOfArray*100;
  let sumOfAll = 0;
  let average = 0;
  let num = 0 ;
  
console.log(lengthOfArray);
  for(let i=1;i<=lengthOfArray;i++){
  num = scores.shift();
  sumOfAll = sumOfAll + num;
  }
   return sumOfAll/lengthOfArray;
   
}
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]));
console.log(average);

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Hi and welcome to the community!
Why are you logging average to the console? If you notice, you’ve defined average inside the function and then using it outside the function which causes the error.
Good luck!