Review JavaScript Fundamentals by Building a Gradebook App - Step 1

Tell us what’s happening:

Can I help you? I don’t understand this question, and I don’t know how to get a number in a function

Your code so far


// User Editable Region

function getAverage(scores) {
  for (let i = 0; i < scores.length; i++) {
    return 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/124.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 1

the loop is not a bad start, but you should not return the function itself
the average is calculated by summing all numbers together and dividing by the number of numbers

you have scores, the function parameter, which is an array of numbers
you need to sum together all the numbers in this array, and then divide by the number of items in this array.

if you need other variables, feel free to declare them, if you need other things use them, this is totally free in implementation

good start with the for-loop, but you shouldn’t call the function inside the for-loop, instead you should sum all the elements of the array and divide the sum by the number of elements of the array. Good Luck!

sorry, I still don’t understand. Can you explain clearly

what do you not understand? So I know how to explain clearly

Hi @minhtrong24062002 !

A large part of programming is solving problems you have never solved before.
When you encounter a problem, then you should research on google or forums.
Professional developers run into issues all of the time, and they use google all of the time.
That is the skill you are learning and practicing here.

For this problem, you have created the loop but you haven’t added all of the numbers in the array to get the sum.

So what you will need to google is "how to add up a list of numbers for loop javascript"
There are tons of beginner friendly articles showing you how to do that.

Once you get the sum, then you can get the average and the lessons shows you how to do that.
Then you will have completed step 1

hope that helps

thank you, I passed this challenge

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.