Hi, I am just working on the Falsy Bouncer challenge in Basic Algorithms right now, and I don’t understand why it’s not accepting my code. Could somebody help me out and tell me what’s going on? When I console.log all of the arrays it wants to test they all come out with the right answer, but it doesn’t show them as passed…
Any help or feedback would be appreciated, thanks!
function bouncer(arr) {
let result = [];
for (let i = 0; i < arr.length; i++) {
//console.log(i);
if (arr[i]) {
result += arr[i];
result += " ";
}
}
return result;
}
console.log(bouncer([7, "ate", "", false, 9])); // returns 7 ate 9
console.log(bouncer(["a", "b", "c"])); // returns a b c
console.log(bouncer([false, null, 0, NaN, undefined, ""])); // returns []
console.log(bouncer([null, NaN, 1, 2, undefined])); // returns 1 2
It helps to provide the link to the challenge you are working on.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.