$#Falsy Bouncer$%#$

$#Falsy Bouncer$%#$
0

#1

Tell us what’s happening:
Test case 1 ,2 seem conflict with test case 3, 4

Your code so far

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var nwarr = [];
  for (i=0;i<arr.length;i++) 
  {
    if (arr[i] != "false" && arr[i] != "" && arr[i] != 0 && isNaN(arr[i]) == false && arr[i] != null && arr[i] != undefined) 
      {  nwarr.push(arr[i]); }
           
  }  

  return nwarr;

}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:


#2

It’s fully doable, you need to change your logic. Think about what you get when you do isNaN(“ate”) and the behavior of your current code.


#3

Tell us what’s happening:
why isn’t working the code

Your code so far


function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  for(i=0; i<arr.length; i++){
    if(arr[i]==false){
      arr.splice(i,1);
    }
  }
  return arr;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bounce


#4

You are just checking if the element is the false.
Remember every element has a Boolean value. Check that instead.
So if (true) {…}
Then you won’t even have to slice, you can push the values to a new array.