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!
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
Terence Chan11,867 Points
Not quite sure what to do for this code challenge? Could anyone provide a hint or direction please? Thanks
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.
Hugo Paz15,622 Points
First you create a function that receives a parameter, lets say function myFunction(parameter)
Then inside, you need to check if parameter is a string, a number or undefined, if its one of these, you return 0. Else you return the length of the parameter.
I remember this one, because I had (probably the same) problem understanding it. Not on what to do, but how to phrase it.
You either had to do several "if" and "else if" statements testing if it's a "typeof" a string, a number, or undefined, or do it on one line by using the pipe symbol as an "or", so on one line you're testing if it's a "typeof" a string OR a number OR undefined.