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
8 Answers
+ 2
Look at checkCreatures() line 12, you should evaluate by using equality operator `==` rather than assignment operator `=`
return element.habitat == "ocean";
+ 1
Will try that IPang
+ 1
Thanks @Ipang ,it worked
+ 1
steve Purpose It was the case. Ipang just elaborated on what I said cause I pointed out the return statement.
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.
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
0
I didn't really understand the way you put it across @Justice.Thanks all the same.
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.