Falsy Bouncerh no working well

Tell us what’s happening:
can you tell me why my code not achieve
-bouncer([false, null, 0, NaN, undefined, “”])should return` .

-bouncer([1, null, NaN, 2, undefined])should return[1, 2]` .

Your code so far


function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  return arr.filter(x => !(x == NaN || x==false||x==null ||x==0||x==""||x==undefined ) );
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0.

Link to the challenge:

I found this interesting and may help

console.log(Boolean(0 == 0));  // true of course
console.log(Boolean(null == null));  //true
console.log(Boolean(undefined == undefined));  //true
console.log(Boolean(false == false));  //true
console.log(Boolean("" == ""));  //true
console.log(Boolean(NaN == NaN));  //false

NaN is the problem but I wasn’t able to fix your code using all the || to make it work. It might need a different approach unless someone has an idea for your approach.

This is a common misunderstanding with the Falsy Bouncer. You can make a solution for this challenge which tests against a hardcoded list of falsy values, but it misses the point of the exercise. The concept of values being “falsy” isn’t something made up by Free Code Camp for the purposes of this challenge, but rather a quality that values have in programming languages. A value is falsy if the language treats the value as false when it is evaluated as a boolean. This means that Boolean(someFalsyValue) is false but also that we can use it in a conditional like if (someFalsyValue) . We can also talk about values being “truthy”. As I’m sure you’ve guessed, truthy values evaluate to true in a boolean of logical context.

if (someFalsyValue) {
    // this code block is not entered
}
else if (someTruthyValue) {
    // this code block is entered and executed
}
1 Like