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

Help Creating a Function

I think I'm the right track, just getting a tad lost in the syntax. Any suggestions from here?

```function arrayCounter (array[]) { if (typeof parseInt.array[] === 'undefined') { return 0; } console.log(array[].length); }

1 Answer

J Scott Erickson
J Scott Erickson
11,883 Points

Sort of there. Your function will take an argument, which you don't know the type of, the argument will need to be a variable that holds the place of whatever is passed in, as it could come from anywhere in the code and the function itself will have no idea the name of the variable that was passed, only the variable name of the argument in the Parenthesis. You need to check for the three different cases given. a string, and number, or undefined.

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