# Write Higher Order Arrow Functions - Help understanding what I'm doing wrong

Hey everyone,

Wondering if anyone can please help me understand why this code isn’t working for me? I have a feeling that it’s the “squaredIntegers*squaredIntegers” line.

Thanks!

``````const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
"use strict";
// change code below this line
let squaredIntegers = arr.filter(num => num%1===0 && num > 0);
squaredIntegers*squaredIntegers;
// change code above this line
return squaredIntegers;
};
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
``;
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions``````

Yes you are on the right track.

You can use Array.prototype.map() funtion after the filter to calculate the each value in the array of its square values.

Good luck.

1 Like

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

Yes, you are right. Each line isn’t doing what you think it is

1. array.filter returns an array. So your result looks like this `[1,2,3]`
2. you’re multiplying `squaredIntegers*squaredIntegers`,
• but squaredIntegers is an array, so `[] * []`
• and you’re not reassigning the variable squaredIntegers to the result of the multiplication
• `squaredIntegers = ....`

If you get a feeling that something is wrong, console.log it and check it in devtools. You can inspect your variables there.

1 Like

No i did the exact same thing and it works. It just checks for remainders (decimals).

All he needs to do is to map over the array and multiply every item by oneself --> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Currently he is multiplying the array by itself, which as you pointed out, is not possible since its not a number. That is his only error.

1 Like

Correction: every integer is divisible by 1.

You’re right. I brain farted. I read it as the division operator and not the modulus operator. Hence I said every number is divisible.

I corrected my previous response. Good catch

2 Likes

Lol we all make mistakes.

At least you owned up to it

Best of luck

1 Like