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

Stephen Bicker
Stephen Bicker
3,686 Points

Checking for 'undefined'

The project checker keeps telling me to check for 'undefined', yet I am doing just that. What am I missing?

Hi Stephen,

Post what code you have so far so you can get help with what you need to fix.

1 Answer

Jimmy Hsu
Jimmy Hsu
6,511 Points

All you need to do is check for the type with an if loop with 'typeof', then name of your parameter, then is equal to signs. There's multiple ways to do this, but it appears this is how they want you to do it.

Below is one solution.

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