Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

Hello I need help with my code below, I don’t know how to do it,

Your code so far


// User Editable Region

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


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

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

you have the loop for what reason? you never use i, and you just do that calculation. Also right now sum is 0, you need to calculate it to have a proper average

Step 1:
Use the for loop to iterate through the scores array and calculate the sum of its items.

Step 2:
Outside of the for loop, calculate the average by using the statement you wrote:

average = sum/scores.length;

Remember to declare average first.

Step 3:
return the average value.

function getAverage(scores) {

let scores = 0;

for(let i=0;i<scores.length;i++){

sum+=scores[i];}

}

this is my first step ,

you have an issue, the function parameter is scores, then you create a variable scores losing access to the function parameter

do not use the name scores for this variable

Thnx for help i got the code done.