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 trialStephen Bicker
3,686 PointsChecking for 'undefined'
The project checker keeps telling me to check for 'undefined', yet I am doing just that. What am I missing?
1 Answer
Jimmy Hsu
6,511 PointsAll 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;
}
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Stephen,
Post what code you have so far so you can get help with what you need to fix.