Tell us what’s happening:
There seems to be a glitch in the test runs as I got 71.7 & 85.4 as results. Help me please.
Your code so far
// User Editable Region
function getAverage(...numbers) {
const sum = numbers.reduce((acc, curr) => acc + curr, 0);
return sum / numbers.length;
}
const result = getAverage(92, 88, 12, 77, 57, 100, 67, 38, 97, 89)
console.log(result);
const result2 = getAverage(45, 87, 98, 100, 86, 94, 67, 88, 94, 95)
console.log(result2);
// 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/127.0.0.0 Safari/537.36 Edg/127.0.0.0
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 1
toan
2
Hi there,
This is the given code:
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]));
As you can see, the getAverage
function takes only one parameter which is an array.
Also can you send me a link to Scrimba please?
It means you should read the exercise again.
If you don’t understand something then you should ask a specific question about what you did not understand.
For eg you could say:
I see that you said that the function should take one parameter which is an array but isn’t that the same as using a spread operator?
The answer in this case would be no.
Please do not change the function parameter and use it as it is given to solve the problem.
If you reset the step, you will see the argument for the function is in square brackets
getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])
This makes it 1 array
You’ve removed the square brackets:
getAverage(92, 88, 12, 77, 57, 100, 67, 38, 97, 89)
Now it’s 10 different arguments you are passing.
Reset the step, read the instructions and just do what the instructions say, and nothing else.
Complete the getAverage
function which takes in an array of test scores and returns the average score.
It says here the function should take an array as an argument, and this part is already done for you. No need to change it.