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 trialChristian Lawrence
3,941 PointsReturn Values
I can't work out what I'm doing wrong here, seem to keep getting the wrong return value.
The function must return the length of an array passed in or 0 if a 'string', 'number' or 'undefined' value is passed in.
Bummber! Wrong value returned from 'arrayCounter("string")' it should be 0
function arrayCounter (dog) { if (typeof dog === 'undefined'){ return 0; } return dog.length; } arrayCounter('bulldog');
2 Answers
Ron McCranie
7,837 PointsIt wants you to test if it's undefined, string, or number. Try this:
function arrayCounter(stuff) {
if(typeof stuff === 'string' || typeof stuff === 'number' || typeof stuff === 'undefined') {
return 0;
} else {
return stuff.length;
}
}
Christian Lawrence
3,941 PointsChristian Lawrence
3,941 PointsCheers I understand now, didn't know about the ||