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 trialEric Vandenberg
9,095 PointsStuck in JavaScript challenge
Around line 17, create a function named 'arrayCounter' that takes in a parameter which is an array. The function must return the length of an array passed in or 0 if a 'string', 'number' or 'undefined' value is passed in.
This is what I was trying to submit...any suggestions? Thanks!
function arrayCounter (value) {
if (typeof value === ('string', 'number', 'undefined') {
return 0;
}
else {
return value.length;
}
}
2 Answers
Dave McFarland
Treehouse TeacherYou can't test all 3 values at the same time. You need to run separate tests for each:
if (typeof value === 'string') {
return 0;
} else if (typeof value === 'number') {
return 0;
} else if (typeofvalue === 'undefined') {
return 0;
} else {
return value.length;
}
Eric Vandenberg
9,095 PointsGood to know! Thanks for your help Dave