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 trialSergio Leite
3,675 PointsIs this a bug?
I put the following code:
function arrayCounter (array) { if(typeOf array === "undefined"){ return 0; } return array.length; }
and is showing the message: "Bummer! You're missing a function called arrayCounter!" ah?! :)
2 Answers
Richard Duncan
5,568 PointsYeah you're close though. The typeof method is all lowercase and you're missing the else condition from your if statement.
I've posted a solution below but please take note of the structure of the if statement in the body of the function.
function arrayCounter (array) {
if (typeof array === "undefined") {
return 0;
} else {
return array.length;
}
}
This is the same as saying if array is identical to undefined then return 0. If the value of array is not identical to undefined (i.e. everything else) then return array.length.
Sergio Leite
3,675 PointsYes, I figured that I had a mistake on "typeof", thanks! ;)
But was missing another important point - inside the IF statement we also need to input : typeof array ==="undefined" || typeof array ==="string" || typeof array ==="number"
Thanks! :)
Richard Duncan
5,568 PointsYep and well done for figuring it out! If you found it useful you could mark as correct so as to help someone in future :) glad I could assist!