Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

I can’t seem to create the loop and length properties, i’ve tried a lot, if you can just explain without giving the answer.

Your code so far


// User Editable Region

function getAverage(scores) {length / sum

}
// Initialize sum variable
let sum = 0;

// Iterate using for loop
for (let i = 0; i < getAverage.length; i++) {

	// Add to the number in each iteration
    sum += getAverage[i];
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/132.0.0.0 Safari/537.36 OPR/117.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

The only code you have inside your function is length / sum, which is meaningless as neither term is defined at this point. You’ll need to move the closing curly bracket so that all function code is inside the brackets.

The declaration of your for loop is almost correct but you should be iterating the scores array (not getAverage). Also the loop doesn’t have a closing curly bracket.

Likewise the code inside your for loop (sum += getAverage[i]) should be referencing the scores array too.

Once your for loop has finished running you should then have the total of all of the values in the scores array so, below the loop, you can then return sum, divided by the length of the scores array (using JS’s built-in length property).

I would hit the Reset button and start again.
Initialise the sum variable at the top of your function, then run the for loop, then return sum, divided by the length of scores.