Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Functions Return Values

Andrew Baker
Andrew Baker
4,080 Points

Why am I wrong?

This is the code I have tired and read over several times, I am not sure why or how I am wrong and would love someone to point me in the right direction.

function arrayCounter (array) {

        if (typeof array === "undefined", "string","number") {
          return 0;
        }
    console.log(array.length);
      }

1 Answer

Andrew McCormick
Andrew McCormick
17,730 Points

Andrew,
You're close. First when you are checking the typeof, that needs to be 3 separate checks separated by the "or" operator ( ||), not a comma separated list.
Second, make sure you are returning the length of the array so that it could be used by another function. Logging the value to the console, does just that. It logs it, but doesn't make it accessible if someone was trying to call the arrayCounter function. Just like you returned the value of 0, make sure you return the length.