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 trial

JavaScript JavaScript Foundations Functions Return Values

Stuck 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

Make sure all open braces have a closing brace and all closing braces have a preceding opening brace.

Check the argument you are passing into the function versus what you are using in the body.

Looks 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; } }

You need to check your curly braces and you are using === 'string' twice. You don't have a check for undefined.

Sorry, 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.

Yep, I see it now. Two braces missing. Wow. I must have counted those over a two dozen times or more.

Thanks. Good eye.

Change 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"

function 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???

From what you have copied there, you're missing a "}" at the end.

D'oh! Thanks Russel!