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

Fernando Ramos
Fernando Ramos
4,369 Points

Stage 5 Arrays Functions Arguments Challenge 1

Can someone please help with this crazy challenge? This is the Function Arguments (Return Values) Challenge 1 of 1 Here is what I typed:

  function arrayCounter (myArray) {
    if (typeof myArray === 'undefined' || typeof myArray === 'string' || typeof myArray === 'number') {
        return 0;
  }
    return arrayCounter.length;
  }

"The Challenge question is this: 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 just need to know how this script should work. I tried everything!! :-((

The Challenge reply when I run this is:

"Bummer! If I pass in an array in to 'arrayCounter' of '1,2,3' I get 1 and not the number 3."

1 Answer

Paul Johnson
Paul Johnson
18,924 Points

You have everything right, apart from the second return, it should be myArray.length, not arrayCounter.length.

Fernando Ramos
Fernando Ramos
4,369 Points

Paul you are my hero!! I will name my next kid after you, if I ever have another! I think I just about birthed one out of frustration from this challenge! GeeWiz!!!