Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

I have looked at the answer for this part already and I am still very confused about how it works. I would appreciate it if someone could explain it to me.

Your code so far


// User Editable Region

function getAverage(scores) {

}

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/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

I am not sure you have described what part is confusing you? Is it that you don’t know how to calculate an average or something else?

its not really a certain part but kind of the whole thing. Like I don’t understand why we got a sum which starts at 0, what const score of scores means, how in sum += score we havn’t listed a score value so how is it being add to sum, and how return sum / scores.length would be 0 cuz diving by 0(sum) always equals 0, and where scores.length came from.

I would rather help you try to solve this one yourself than to explain someone else’s solution to you.

Can you determine what you should do first?

Will the first step would be making something to represent the total, like let sum = 0 but after that I got no clue

Okay that sounds reasonable. In order to find the average we need to add up all the numbers first right? So how would we do that if we are given an array called scores?

We would need to find a way to add up all the numbers to the sum

So what comes to mind? What do we know that we can use to add the scores?

See that’s where I am drawing a blank, my first thought is just using + but that wouldn’t work

Becuase the different unknown grades

Look at the tips in the instructions.

1 Like

The function has a parameter called scores. When you call the function pass it an array of numbers, which becomes scores in the function. The array has a property called .length

Thank you all for the help and now I think I fully understand it. I just want to check if my comments are added are correct

solution code removed

Try not to look at the solution in future before trying the exercise yourself. I’ve seen people fail really badly to learn to problem solve because they got into that habit.

Please don’t post your code here. Test it and see if it passes.

If it passes, congratulations.

If it doesn’t pass, you can troubleshoot and are welcome to discuss it here.