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 trialBen Goldman
14,626 PointsStuck on Functions, Stage 5 Code Challenge
The challenge is telling me that I haven't created a function called arrayCounter. I'd appreciate it if someone could help me locate the error. Here is my code. Thanks!
function arrayCounter(object) {
if (typeof array === 'string') {
return 0;} else if (typeof array === 'number')
return 0;} else if (typeof array === 'undefined')
return 0;} else {
return object.length;
}
}
9 Answers
John Kotz
8,591 PointsMake sure all open braces have a closing brace and all closing braces have a preceding opening brace.
John Kotz
8,591 PointsCheck the argument you are passing into the function versus what you are using in the body.
Ben Goldman
14,626 PointsLooks fine to me. I guess I'm not sure what you mean. I tried rewriting it, but I more or less got the same thing.
function arrayCounter(myArray) { if (typeof myArray === 'string') { return 0;} else if (typeof myArray === 'string') return 0;} else if (typeof myArray === 'number') return 0;} else { return myArray.length; } }
John Kotz
8,591 PointsYou need to check your curly braces and you are using === 'string' twice. You don't have a check for undefined.
Ben Goldman
14,626 PointsSorry, but I don't see it. The curly braces seem fine to me. The string typo above was a mistake rewriting the code in the comments. The original code posted at the top is what I'm trying to use.
Thanks.
Ben Goldman
14,626 PointsYep, I see it now. Two braces missing. Wow. I must have counted those over a two dozen times or more.
Thanks. Good eye.
Russell Wood
12,088 PointsChange your input parameter name to "array" if you are going to test against the logic in the condition or change all of your "array"s to "object"
Evan Huddleson
12,623 Pointsfunction arrayCounter(array) { if (typeof array === 'string') { return 0;} else if (typeof array === 'number'){ return 0;} else if (typeof array === 'undefined'){ return 0;} else { return array.length; } //Why doesn't this work???
Russell Wood
12,088 PointsFrom what you have copied there, you're missing a "}" at the end.
Evan Huddleson
12,623 PointsD'oh! Thanks Russel!