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

Tell us what’s happening:

Describe your issue in detail here.
since getMean takes an array as an argument, how can we use 2 arguments when we call it again?

Your code so far

```javascript
/* 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
    ? (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2
    : sorted[Math.floor(sorted.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;
}

Your browser information:

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

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

In what case would you want to pass two arguments?

1 Like

Sorry.
So the code is like this:

const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length;

const getMedian = (array) => {
const sorted = array.sort((a, b) => a - b);
const median = array.length % 2 === 0
? (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2
: sorted[Math.floor(sorted.length / 2)];
}
And it doesn’t pass. Instead I get this message:

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 .

How is it possible to use getMean with 2 arguments since it only one array as an argument?

1 Like

You can’t use getMean with two arguments anywhere. That message is a bit of a mess.

You need to pass an array with two entries.

2 Likes

I was stuck on this for a long time. You do need to pass it an array but it also needs to be in parenthesis. In case this helps anyone else get unstuck