Learn Advanced Array Methods by Building a Statistics Calculator - Step 22

it’s giving me this error If the `array.length` is even, your `median` variable should use the `getMean` function to calculate the mean of the two middle numbers. Your first argument should be the value of `sorted` at `array.length / 2` , and the second at `array.length / 2 - 1` .

``````/* file: script.js */
const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length;

/* User Editable Region */

const getMedian = (array) => {
const sorted = array.sort((a, b) => a - b);
const median = array.length % 2 === 0 ? getMean(sorted[array.length / 2], sorted[array.length / 2 - 1]) : sorted[Math.floor(array.length / 2)];
}

/* User Editable Region */

const calculate = () => {
const value = document.querySelector("#numbers").value;
const array = value.split(/,\s*/g);
const numbers = array.map(el => Number(el)).filter(el => !isNaN(el));

const mean = getMean(numbers);

document.querySelector("#mean").textContent = mean;
}
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`

Challenge Information:

Learn Advanced Array Methods by Building a Statistics Calculator - Step 22

Check the parenthesis of the getMean argument.

Happy coding

Hey,
I don’t think it’s syntax error

It is not a syntax error. All I can say without giving the answer is to check the argument parenthesis.

I have double checked everything didn’t find anything

Hey,
If you know where I am making a mistake please tell me i am stuck here

In the median variable the getMean function needs to take a parameter.
That parameter needs to be in the form of an array.

In the current form, the getMean function in median has parameters, but they are not nested inside an array.

6 Likes

Thank you so much Teller, I was stuck here for a while too and it never even occured to me to use as the getMean takes array as an input. Thanks again!

1 Like

yup was stuck on that too but checked the code above and say that it takes an array

1 Like

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