Lodash project findKey()

When I run the test in Codecademy for findKey() I pass everything. With no problems, but when I use the same code in Visual Studio Code I get this error53

And if I would remove

let predReturnValue = predFunction(values);
and replace
if (predReturnValue)
with
if (values === predFunction)

I get no errors in Visual Studio Code, and it’s working as it’s supposed to.

but if I do the same in Codecademy I don’t pass the test.

How come this is happening?
What is right and what is wrong?

(More Pictures in the comments since I could only upload 1)

Can only upload 1 image, so guess I upload the rest in comments.

This is the first code in Codecademy

This is the new code in Visual Stuido Code

This is the new code in Codecademy

Hello, @patrik9006773596.

Welcome to the forum.

The difference in the two environments is the second argument passed to your findKey function. The second argument needs to be a function. If you click on the folder icon in the upper left corner of the Codecademy code editor, you can inspect the test folder, and specifically the find-key.js file in the folder. You’ll see a very simply function called startsWithV defined:

const startsWithV = string => string.startsWith('v');

When you type the command node test/find-key.js in the bash console, your function is called/tested with the following:

_.findKey({"key": "value"}, startsWithV)

In your VS code environment, you could define the same startsWithV function, or use one of your own choosing. The important thing is that the 2nd argument should be a function not simply a value.

1 Like

Ah, thank you, I understand :slight_smile:

1 Like