Tell us what’s happening:
Describe your issue in detail here.
My code look legit but it dont working, i tired put in visualizer it cant detect
false may i know why?
**Your code so far**
for (let i = 0; i < arr.length; i ++)
if(arr[i] === false || arr[i] === null || arr[i] === "" || arr[i] === undefined || arr[i] === NaN || arr[i] === 0)
bouncer([7, "ate", "", false, 9]);
**Your browser information:**
User Agent is:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/184.108.40.206 Safari/537.36
Challenge: Falsy Bouncer
Link to the challenge:
congrats! If you passed the challenge. your code has some issues it might help you in future challenges.
there is a space between i and ++ and splice is reducing arr size but your for loop does not know about it, may be array out of bound error occur
oops that a mistake but i fixed it still cant working , anyway thanks for telling me the mistake
This lesson is trying to drive home that the condition in
if statements is checking truthiness already.
splice mutates the array that you’re looping over. This is bad, because the loop termination depends on the
i value and the array’s length, but the length keeps changing. A better approach is to do the opposite, build up a new array of values you want to keep, and return that new array at the end.
June 3, 2022, 12:47pm
arr[i] === NaN
NaN === NaN is false
so thats why it doesnt execute the code because have
two false in the statement?
what do you mean that it doesn’t execute? are you getting a syntax error?
i dont understand what you mean by
Nan === Nan is false
NaN === NaN is not
true, it is
false. You can’t check if a value is
NaN by using the strict equality operator.
I see … i get it now thanks!
December 4, 2022, 8:57pm
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.