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.

Serafeim Oikonomou
6,028 PointsChallenge problem
Hello!
The challenge is:
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.
My code:
function arrayCounter(myarray){
if (typeof myarray==="undefined") || (typeof myarray==="string") || (typeof myarray==="number") {
return 0;
} else {
return myarray.length;
}
}
I get "SyntaxError: Parse error" Any suggestions??
3 Answers

Johnny Chau
2,616 Pointstry wrapping all 3 "if" conditions in a pair of parentheses like: if ((typeof myarray==="undefined") || (typeof myarray==="string") || (typeof myarray==="number"))

Joakim Bergman
14,501 PointsThere should be another set of parentheses around all of the conditions like this if ( ( typeof myarray === "undefined ) || ( typeof myarray === "string" ) || ( typeof myarray === "number" ) )

Serafeim Oikonomou
6,028 PointsI already did it. Thank very much for your replies though :-)