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
Kevin Silvestre
13,561 PointsI can't pass this 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.
My answer:
var family = ["jim", "is", "here"];
function arrayCounter(family){
return family.length;
if(typeof family === 'undefined'){return 0;}
if(typeof family === 'string'){return 0;}
if(typeof family === 'number'){return 0;}
}
what am I doing wrong? I am doing everything I am asked to.
link to challenge http://teamtreehouse.com/library/return-values
Kevin Silvestre
13,561 Pointsthis is the link to the challenge http://teamtreehouse.com/library/return-values
3 Answers
James Barnett
39,199 PointsEverything after a return isn't executed, so move the return statement that isn't in a conditional, to bottom of the function.
Kevin Silvestre
13,561 Pointsthank you very much, I spent 5 hours trying to solve this problem. Thanks a lot.
James Barnett
39,199 Points2 quick thoughts on getting stuck on a problem ...
- I had a programming instructor in college that used to say, half of all problems can be solved by going to lunch.
- I've been trying to get better about asking for help after an hour or 2.
Kevin Silvestre
13,561 Pointsok. thanks I will keep it in mind for next time,
James Barnett
39,199 PointsJames Barnett
39,199 PointsWithout a link to the challenge, someone has to search around and guess which one could be until they find the right one, if they want to test out their solution.