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

Devin Scheu
Devin Scheu
66,191 Points

Help With Arrays

Around line 17, create a function named 'arrayCounter' that takes in a parameter which is an array. The function must return the length of an array passed in or 0 if a 'string', 'number' or 'undefined' value is passed in.

I srsly have no clue how to do this/

2 Answers

Sreng Hong
Sreng Hong
15,083 Points

Hi Devin, I get through this challenge by this code:

function arrayCounter (p_array) {
        if (typeof p_array === 'string' || typeof p_array === 'number' || typeof p_array === 'undefined') {
          return 0;
        }
        else {
          return p_array.length;
        }
}
Chris Shaw
Chris Shaw
26,676 Points

Hi Devin,

I made a detailed answer in another thread about this as I believe it should have been explained the way I did in my reply. https://teamtreehouse.com/forum/stuck-on-stage-5-functions-quiz