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

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;
  }
}