I have read the solution and I totally get it. Although I never would have reached that solution on my own in a million years.
I would like to finish the code that I started just so I know that I can at least make it work. Can someone please review my code? And answer this question:
1 - Why is
console.log(arr[i]);
returning only the truthy elements but
arr1.push(arr[i]);
builds an array with ALL elements of arr?
Thank you.
Your code so far
function bouncer(arr) {
// Don't show a false ID to this bouncer.
//Build an array of just falsy values
// var arr1 = [false, null, 0, "", undefined, NaN];
var arr1 = [];
//Go through test array to see if any elements match falsy values
for (i=0; i<arr.length; i++){
if (arr[i] == false) {
//do nothing
}else
console.log(arr[i]);
arr1.push(arr[i]);
}
console.log(arr1);
// return arr1;
}
// bouncer([7, "ate", "", false, 9]);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/falsy-bouncer