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 trialantonio ortiz
2,059 PointsI keep getting 'You're not checking if 'undefined' is being passed in'....
This is my code...
function arrayCounter(array){
if(array){
return array.legnth;
}else{
return 0 === '' && !NaN || undefined;
}
}
3 Answers
John W
21,558 PointsHmmm... your syntax is way off. Looks like you have some fundamental misunderstanding of the if/else syntax and type-checking. All the answers you need to fix it are available in this single video:
http://teamtreehouse.com/library/javascript-foundations/variables/null-and-undefined
antonio ortiz
2,059 PointsHey thanks John, You're right! As I looked back at the video I see now how 'type checking' was the theme however it doesn't come across really in the question.
This is what seems to get you passed the challenge...
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;
What I found interesting was when I punched in
typeof 'undefined';
in the console it spits back string? And shouldn't !NaN be better suited instead of 'number' and wouldn't it be undefined without quotes?
I appreciate your help!
antonio ortiz
2,059 PointsHey thanks John, You're right! As I looked back at the video I see now how 'type checking' was the theme however it doesn't come across really in the question.
This is what seems to get you passed the challenge...
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;
What I found interesting was when I punched in
typeof 'undefined';
in the console it spits back string? And shouldn't !NaN be better suited instead of 'number' and wouldn't it be undefined without quotes?
I appreciate your help!