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

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!!!