so if you were learning javascript how would go about solving this problem? I was using chat gpt and it worked for 99% of the time but someone encouraged me not to use chat gpt or copying a solution on the forum.

ChatGPT is cheating. Youâ€™re not writing the code. Youâ€™re not learning. Youâ€™re not getting better at writing code.

It is also a known liar.

You also really shouldnâ€™t just copy solutions from the forum. Again you arenâ€™t learning or thinking about how the code works.

so without being vague how would you go about solving this?

Your goal is to complete the `getAverage` function which takes in an array of test scores and returns the average score. What exactly have you tried so far?

before i messaged you i copied this from geeks4geeks and then modified it.

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

}

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]));
``````

Iâ€™ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the â€śpreformatted textâ€ť tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Does this return the correct result?

If not, in what way is it incorrect?

Do you get any errors in the console or hint messages?

Youâ€™ve made a `for` loop. When do you intend the loop to stop?

the backtics arent going to help with the step 1 challenge.
heres my result

``````// running tests
Your getAverage function should return a number.
getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]) should return 71.7.
getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]) should return 85.4.
getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100]) should return 92.4.
Your getAverage function should return the average score of the test scores.
// tests completed
``````

right now im going through all the tutorials again since i forgot everything.

Have a review of the syntax of a `for` loop, there is an error there.

To create a for loop you need to give it the following information

1. declare a variable with an initial value
2. declare a condition that evaluate to `true` for the loop to continue
3. increment

isnt this true? I dont know what else to do with it

``````getAverage.length;
``````

i dont see whats wrong with the increment
`i++`

Were you able to review how a for loop works?

Yes, itâ€™s truthy, but usually you will have a condition that limits `i` in some way, like this:

``````for (let i = 0; i < 10; i++) {
}
``````

So when `i` gets larger than 10 the loop will end.

Have you notice that getAverage is the name of the function and that the actual data will be pass as a parameter and should be inside the scores variable?

getAverage is not an array therefore it does not have a length property.

im in the middle of doing that ill get back to you

yeah i have noticed getAverage is the name of the function. the rest I dont know

by the way if someone is 44 learning this stuff whats the likelyhood of someone hiring them?

ok i went through some of the tutorials and look at some articles on freecodecamp but nothing seems to help. i just see examples of for loops but nothing like the example for this problem im trying to solve.

Letâ€™s start with the function you wrote, which has the basic structure, but it needs some work.

You are making a function. It takes `scores` as a parameter, which is an array of scores like this `[92, 88, 12, 77, 57, 100, 67, 38, 97, 89]`

The output will be the average of all the scores, correct?

Can you write out the steps, just in words not code, what the loop will need to do and what to do at the end? How do you get an average of a group of numbers?

1. add all the numbers which is 10 of them.
2. then divide the total number by the amount of scores

Thatâ€™s it, perfect, no more to it than that!

Letâ€™s break the 1st step into smaller steps. We know we are going to code a loop. We have a list, and sum init to 0:

``````[92, 88, 12, 77, 57, 100, 67, 38, 97, 89]
let sum = 0;
``````

The loop will use the variable `i`, which will start at 0

``````for (let i = 0;
``````

`i` will increment by 1 on each iteration of the loop:

`````` for (let i = 0;              ; i++) {
``````

The loop will take each number from the array and add it to `sum`. What will the maximum value of `i` be?