Falsy Bouncer code not accepted... don't know why?

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++) {
    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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

The lesson says to remove all false values from the array, not to convert the return value to a string…

1 Like

What is going on here? You are treating result like a string? Do you remember the syntax for adding something to an array?

1 Like

Hi @geoff.ijamieson !

Welcome to the forum!

I edited your post to include the challenge link.

When making posts on the forum please provide all of the information so we can best assist you.

thank you for your help

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.