Function missing - Higher order arrow function

Tell us what’s happening:
I have resolved the problem but I get this message:
function keyword was not used.
What is this “function” keyword that I should use??

Your code so far

    return num * (num)});
```js

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];


const squareList = (arr) => {
  "use strict";
  // change code below this line
    const squaredIntegers = arr.filter (num => num > 0 && Number.isInteger(num)).map(function(num) { 
    return num * (num)});
  // change code above this line
 
  return squaredIntegers;
};


// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);

// const longWords = words.filter(word => word.length > 6);
// Number.isInteger(2)

// var roots = numbers.map(function(num) {
// return Math.sqrt(num)
// });

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions

Actually you shouldn’t use function keyword, you used it here. Instead you should use arrow function

Hello! You are using the keyword function, but function is not being defined anywhere.

Another thing, in my solution I did not need to use this return:

Note that there is already a return below.

That return and the return below are two different scopes, so they are independent. One is the return of the callback function, the other of the function you are building

Also, that is an anonymous function, doesn’t need to be defined. The issues lies elsewhere.

Well, there, but it is an other thing

Welcome to the forum @federicozinelli!

The message you are seeing is saying that you should use an arrow function like how you defined your squareList function instead of using function like how you did inside your .map. The exercise seems to be to use arrow functions, so changing that function definition to an arrow function should let you pass the challenge.

Thank you Chris-Tse,

So I have modified the code to use arrow functions in both the filter() and map() functions…

const squaredIntegers = arr.filter(num => num > 0 && Number.isInteger(num)).map(num => num * num);
  return squaredIntegers;

I still get the same error message!
However, the result is correct…
Any idea?

If that is the only change you did… try reloading the page, sometimes the tests get stuck

1 Like