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

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!