0

Please why is my array filter returning lion

I am trying to return an array with elements that have an ocean habitat https://code.sololearn.com/W1ghG2VMsoCi/?ref=app

25th May 2022, 3:53 PM
steve Purpose
steve  Purpose - avatar
8 Answers
+ 2
Look at checkCreatures() line 12, you should evaluate by using equality operator `==` rather than assignment operator `=` return element.habitat == "ocean";
25th May 2022, 4:16 PM
Ipang
+ 1
Will try that IPang
25th May 2022, 4:28 PM
steve Purpose
steve  Purpose - avatar
+ 1
Thanks @Ipang ,it worked
25th May 2022, 4:32 PM
steve Purpose
steve  Purpose - avatar
+ 1
steve Purpose It was the case. Ipang just elaborated on what I said cause I pointed out the return statement.
25th May 2022, 4:35 PM
Justice
Justice - avatar
0
I believe it's because your check function is taking every key element passed into it and making the value ocean based on the return statement. I may be wrong though.
25th May 2022, 4:04 PM
Justice
Justice - avatar
0
@justice I don't think that's the case,that's the pattern I use on some other occasions and it has always worked
25th May 2022, 4:31 PM
steve Purpose
steve  Purpose - avatar
0
I didn't really understand the way you put it across @Justice.Thanks all the same.
25th May 2022, 4:44 PM
steve Purpose
steve  Purpose - avatar
0
steve Purpose When I said "Your check function..." the check function is checkCreatures(). "...is taking every key element passed into it... " The Key would be "lion". "... and making the value ocean... " The value was "jungle" and turned it into "ocean". "...based on the return statement." This is where Ipang expands on what I said and tells you that you should that instead of using the assignment operator, you should use the equality.
25th May 2022, 4:54 PM
Justice
Justice - avatar