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

Toni Caktas
Toni Caktas
16,478 Points


Stuck on the return value Callenge task

Richard Duncan
Richard Duncan
5,568 Points

Please post code & question

Dave McFarland
Dave McFarland
Treehouse Teacher

Yeah, which part of the code challenge are you stuck on?

1 Answer

Henry Goh
Henry Goh
20,201 Points

Hi Toni, First you need to create a function called arrayCounter which takes in an Array object. So your function should look something like this:

function arrayCounter(array)

The question also asks to return 0 if the parameter type is either a string, number, or undefined instead of an Array object.

So in your method body, you need to enter an if statement to check the input parameter. if(typeof array === "undefined" || typeof array === "string" || typeof array === "number")

Return a 0 if the condition of the if statement is true. Return the length of the array object if the condition is false.