NaN type data didn't detect

Tell us what’s happening:
I got an error when I want to filter with NaN, other type data is correct, but this one isn’t

Your code so far


function bouncer(arr) {
let newArr = [];
for (let i = 0; i < arr.length; i++){
  if (arr[i] === false | arr[i] === "" | arr[i] === 0 | arr[i] === null | arr[i] === undefined | arr[i] === NaN){
    continue;
  }
  newArr.push(arr[i]);
}
return newArr;
}

bouncer([7, "ate", "", false, 9]);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Falsy Bouncer

Link to the challenge:

You cannot check if a number is equal to NaN. In this challenge, you need to use the idea of Falsy instead checking against a magical list of values. A variable is Falsy if it is treated as False in a conditional, such as

if (someTruthyValue)
  console.log("This is not equivalent to False")
else
  console.log("This is equivalent to False") 

Got it, i understand. I will tried first.

Thank you, i completed that lesson.

1 Like