Learn Functional Programming by Building a Spreadsheet - Step 97

Tell us what’s happening:

My ‘even’ function looks correct but get:
// running tests
Your even function should take a nums parameter.
Your even function should return the result of calling the .filter() method on nums.
You should pass a reference to your isEven() function as the callback for the .filter() method.
// tests completed

const even = (nums) => nums.filter((num) => isEven(num));

### Your code so far


```html
<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const isEven = num => num % 2 === 0;
const sum = nums => nums.reduce((acc, el) => acc + el, 0);
const average = nums => sum(nums) / nums.length;
const even = (nums) => nums.filter((num) => isEven(num));
const spreadsheetFunctions = {
  sum,
  average,
  median,
  even
}

// 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:

Learn Functional Programming by Building a Spreadsheet - Step 97

I think a reference to ‘isEven’ is just ‘isEven’

1 Like

Where is the following code from the challenge:

const median = nums => {
  const sorted = nums.slice().sort((a, b) => a - b);
  const length = sorted.length;
  const middle = length / 2 - 1;
  return isEven(length)
    ? average([sorted[middle], sorted[middle + 1]])
    : sorted[Math.ceil(middle)];
}

Reset step.

The statement asked should be found within spreadsheetFunctions, inline with the ‘even’.

I had tried:

const even = nums => nums.filter(isEven);

But received the same errors.

the variable ‘const even’ is not a valid object property.
the word even by itself is a property they want.

i don’t have this code in my step (as mentioned by DobarBREND you seem to have deleted some code and added code in the wrong location), so you should definitely reset and retry this step.
You only need to add one property to the object.

I reset the step and added the following:

const even = nums => nums.filter(isEven);

Then I added the even function to the spreadsheetFunctions object:

const spreadsheetFunctions = {
  sum,
  average,
  median,
  even
}

And I get:
// running tests Your
even function should take a nums parameter.
Your even function should return the result of calling the .filter() method on nums .
You should pass a reference to your isEven() function as the callback for the .filter() method.
// tests completed

This is a variable called even.
But they don’t want a variable called even.
They want you to update the object and add a property called even.
Do you remember how that’s done?

That’s what I did here:

const spreadsheetFunctions = {
  sum,
  average,
  median,
  even
}

Guess they wanted it done different than all the other properties:

Mod edit : solution removed

Hi, I removed your solution as we don’t want to post full solutions for steps here on the forum. (Just hints and tips). Thx.

you cannot use an “=” in an object to declare properties. There is another way of declaring properties.