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

Tell us what’s happening:

You should assign the result of finding the median of the testArr2 to the evenListMedian variable. Refer back to the example for extra help.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="./styles.css" />
    <script src="./script.js"></script>
    <title>Statistics Calculator</title>
    <h1>Statistics Calculator</h1>
    <p>Enter a list of comma-separated numbers.</p>
    <form onsubmit="calculate(); return false;">
      <label for="numbers">Numbers:</label>
      <input type="text" name="numbers" id="numbers" />
      <button type="submit">Calculate</button>
    <div class="results">
        The <dfn>mean</dfn> of a list of numbers is the average, calculated by
        taking the sum of all numbers and dividing that by the count of numbers.
      <p class="bold">Mean: <span id="mean"></span></p>
        The <dfn>median</dfn> of a list of numbers is the number that appears in
        the middle of the list, when sorted from least to greatest.
      <p class="bold">Median: <span id="median"></span></p>
        The <dfn>mode</dfn> of a list of numbers is the number that appears most
        often in the list.
      <p class="bold">Mode: <span id="mode"></span></p>
        The <dfn>range</dfn> of a list of numbers is the difference between the
        largest and smallest numbers in the list.
      <p class="bold">Range: <span id="range"></span></p>
        The <dfn>variance</dfn> of a list of numbers measures how far the values
        are from the mean, on average.
      <p class="bold">Variance: <span id="variance"></span></p>
        The <dfn>standard deviation</dfn> of a list of numbers is the square
        root of the variance.
      <p class="bold">
        Standard Deviation: <span id="standardDeviation"></span>
/* file: styles.css */
body {
  margin: 0;
  background-color: rgb(27, 27, 50);
  text-align: center;
  color: #fff;

button {
  cursor: pointer;
  background-color: rgb(59, 59, 79);
  border: 3px solid white;
  color: white;

input {
  background-color: rgb(10, 10, 35);
  color: white;
  border: 1px solid rgb(59, 59, 79);

.bold {
  font-weight: bold;
/* file: script.js */
const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length;

// User Editable Region

const testArr1 = [1, 2, 3, 4, 5];
const testArr2 = [1, 2, 3, 4, 5, 6];
const isEven = testArr2.length % 2 === 0;
const oddListMedian = testArr1[Math.floor(testArr1.length / 2)];
const evenListMedian = (testArr2[[testArr2.length / 2, testArr2[(testArr2.length / 2)]);

// User Editable Region

const getMedian = (array) => {
  const sorted = array.sort((a, b) => a - b);

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 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

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

Hey there is errors here in your code however even with what I think is the solution is still not passing.
const evenListMedian = (testArr2[[testArr2.length / 2, testArr2[(testArr2.length / 2)]);
console.log(evenListMedian); you need two brackets at the end and remove one and place at the front also you have parenthese inside those need removed. also you have the same thing twice.
The FCC console is coming back with you need a variable evenListMedian over and over I suggest you contact support.

In the case of an array with even number of items, you need to get the two middle numbers and calculate the mean for them.


let arr = [1, 2, 3, 4];
let secondMiddle = arr[arr.length / 2];    // arr[2]
console.log(secondMiddle);     // 3

let firstMiddle = arr[arr.length/2 - 1];    // arr[1]
console.log(firstMiddle);  // 2

now you have the two middle numbers, you can use the getMean function which takes an array of numbers as a parameter.
(you wrote this function in previous steps)

console.log(getMean([firstMiddle, secondMiddle]));   // 2.5

Try to read the challenge again and understand the example provided, and you will get it.

Thank you! I have tried everything & nothing is working for me. I have been stuck on this for days.
const evenListMedian = [testArr2[testArr2.length / 2] , testArr2[testArr2.length / 2 - 1]];

Hi @missjhoward

  1. To find the median, you can use the getMean function which adds the middle numbers and divides the sum by 2.

You need to use the getMean function.

  1. Then, log the evenListMedian variable to the console.

Happy coding

That’s what I thought I was doing. Can someone please help me figure this out. I am stuck. And have been for a week now. Any hints or help would be appreciated.

const evenListMedian = (getMean[testArr2.length / 2, testArr2.length / 2 - 1]);

I finally got the answer. Thanks for all the help.

1 Like