Tell us what’s happening:
Am confused, how can l complete the getAverage function which takes in an array of test scores and returns the average score?
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 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 1
ILM
June 5, 2024, 7:34am
2
what have you tried so far? the instructions give you various tips from which you can start
yeah, the tips are just confusing me
ILM
June 5, 2024, 7:36am
4
Do you know how to manually calculate the average of a set of numbers?
yes l do, sum the scores then divide by the total number of scores
ILM
June 5, 2024, 7:38am
6
let’s start from summing the scores, you have an array, you need to sum all the elements in the array to each other.
How could you do that?
am still confused, do l just go on and sum up the array of the first scores in the getAverage function body?
ILM
June 5, 2024, 7:54am
8
You use the scores
parameter to access whatever array the function is called with
still not getting, can l have like an illustration of what you are trying to mean?
ILM
June 5, 2024, 7:59am
10
A function is created with parameters, in this case scores
, the value of the parameter is determined when the function is called, so
Samuel18:
getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])
here the value of scores
is [92, 88, 12, 77, 57, 100, 67, 38, 97, 89]
Am defeated, l have tried several times but l’ve failed. l need help with everything or step
ILM
June 5, 2024, 8:28am
12
show your code, it’s the best way to get help
Tell us what’s happening:
How can l complete the getAverage function which takes in an array of test scores and returns the average score?
Your code so far
// User Editable Region
function getAverage(scores) {
let sum = 0;
for (let i = 0; i < scores.length; i++) {sum += scores[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; rv:126.0) Gecko/20100101 Firefox/126.0
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 1
l have posted a new chat to show the code so far
ILM
June 5, 2024, 8:36am
15
what issue are you having? it looks like you are summing the values inside scores
correctly
now you need to finish calculating the average and write the return statement
Can you illustrate how am to calculate the average and write the return statement?
toan
June 5, 2024, 8:46am
17
You got the sum
.
Now return sum
divided by (numbers of elements in scores
array).
How to count numbers of elements in scores
array?
ILM
June 5, 2024, 8:49am
18
you said yourself that the average is the sum divided the number of items. You can easily get the number of items, it is a property of arrays
thanks guys, it has passed, l really appreciate your help
system
Closed
December 4, 2024, 9:03pm
20
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.