Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Functions Return Values

SL Starr
SL Starr
17,543 Points

Need help with challenge!

Hi, I have been unable to pass the challenge for return values in Javascript stage 5 (teamtreehouse.com/library/return values) I am using the code function arrayCounter (Array) { if (Array === "string", "number", "undefined") { return 0; } return Array.length; } I can't seem to find the proper coding to get past the error stating "if I pass in an array I get 0 not 3"

A hint to help with severe mental block. I have rewatched the lead in vids several times and can't seem to grasp the missing component!

Thanks a bunch!

2 Answers

Hi SL,

To begin with, don,t capitalize Array. Also, Javascript needs to know the typeof array being compared (ie. typeof array === "string"). And you have to explicitly say typeof every time you compare another type ( ie. "number"). Also in the if statement you need to use the or || operator in between each typeof comparison.


SL Starr
SL Starr
17,543 Points

Thanks for the help, it quickly got me over this hurdle and is greatly appreciated!