Tell us what’s happening:
hi. I have been stuck on this first step for a while now and have researched how to code a for loop to return the sum of the grades in our given array. I then went on to use the .length array property to return the avg and still can’t seem to pass the tests. does anyone have advice?
Your code so far
// User Editable Region
function getAverage(scores) {
for (let i=0; i < scores.length; i++){
let sum = 0;
sum += scores[i];
return sum
}
let avg = sum / scores.length;
return avg;
}
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 1