Falsy Bouncer- Hint

Tell us what’s happening:

Hello guys, as usual i have a method that i poping up in my mind about how to solve this problem, but the combination i have tested are not working as expected!! please can someone review and tell me where did i mistaken and why the code is not behaving normally

Your code so far

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  function isNotFalsy(arg){
    return arg !== undefined || arg !== false ||  arg !== null || !isNaN(arg) || arg !== 0 || arg !== "";
  return arr.filter(isNotFalsy);

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:

You have two issues:

  1. Your use of the OR operator || makes it so that if ANY of the conditions evaluates to true, the item is kept in the filtered array.

  2. If you were to use the AND operator &&, then !isNaN(arg) would evaluate to false for non-empty strings like “a”.

This challenge introduces you to the concept that there are only 6 values that are “Falsy”. Meaning, the rest are “Truthy”.

HINT: Remember, that the filter callback function is expecting a true or false value (Boolean), so it will attempt to coerce any value returned as true or false. Think about how you could use this to your advantage.

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 or logical context.

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

I will try to take this hint and see what is going to be the value

i will try to take you guideline to see with what i come up with