Learn Functional Programming by Building a Spreadsheet - Step 25

Tell us what’s happening:

Hi! I have no idea what’s happening here but I’ve double-checked and triple-checked my work and can’t find an error. I keep getting the error message “You should use the ‘return’ keyword” but I included it from the first attempt and I don’t know if I’m just missing something obvious or if the error message is misleading or irrelevant (and the error has to do with a different part of the return call).

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" />
    <title>Functional Programming Spreadsheet</title>
    <div id="container">
    <script src="./script.js"></script>
/* file: styles.css */
#container {
  display: grid;
  grid-template-columns: 50px repeat(10, 200px);
  grid-template-rows: repeat(11, 30px);

.label {
  background-color: lightgray;
  text-align: center;
  vertical-align: middle;
  line-height: 30px;
/* file: script.js */
const isEven = num => num % 2 === 0;
const sum = nums => nums.reduce((acc, el) => acc + el, 0);
const average = nums => sum(nums) / nums.length;

// User Editable Region

const median = nums => {
  const sorted = nums.slice().sort((a, b) => a - b);
  const length = sorted.length;
  const middle = (length - 1) / 2;

  return isEven(length)
    ? average([sorted[middle], sorted[middle + 1]])
    : Math.ceil(sorted[middle]);

// User Editable Region

const range = (start, end) => Array(end - start + 1).fill(start).map((element, index) => element + index);
const charRange = (start, end) => range(start.charCodeAt(0), end.charCodeAt(0)).map(code => String.fromCharCode(code));

window.onload = () => {
  const container = document.getElementById("container");
  const createLabel = (name) => {
    const label = document.createElement("div");
    label.className = "label";
    label.textContent = name;
  const letters = charRange("A", "J");
  range(1, 99).forEach(number => {
    letters.forEach(letter => {
      const input = document.createElement("input");
      input.type = "text";
      input.id = letter + number;
      input.ariaLabel = letter + number;

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 25

I think it’s because of this line here:

: Math.ceil(sorted[middle]);

Reason being, sorted is an array and middle is the index you’re using. In this case you want to round the index, not the array. See if that works

Hi @anniebkoop

In addition to the good advise from @rustedviking , you modified the middle variable which the instructions did not ask you to do.

Here is the original.

const middle = length / 2 - 1;

Happy coding

1 Like

Please do not give the solution. The goal of the forum is to help others understand what they are struggling with.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.