Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

I have gotten the code to work without the return method, but I can’t get a pass due to not using a return method.
How do I use the return method I don’t understand what they’re asking me to do

Your code so far


// User Editable Region

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

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/125.0.0.0 Safari/537.36 Edg/125.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

don’t return the function itself, delete this line and add the return keyword so that it returns the average

you should also delete these, or move them inside the function

Yeah I just got it to work thank you, it’s just the error message telling me to return getAverage() is what threw me off

there is no message saying to return getAverage(), where did you see that?

when I would submit my code to kind of test it when it wasnt done on the “check the code” section i’d get a message saying i need to return getAverage()

no you don’t
image

“Your getAverage function should return a number”, that’s what confused me sorry, I took it as needing to call “return getAverage()” in order to do the code. It’s early in the morning I haven’t fully woken up yet