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 trial5 Answers
Joseph Potts
11,187 PointsThis is a syntactic error. Here is the amended code:
function arrayCounter(ar){
if (typeof ar === 'undefined' || typeof ar === 'number' || typeof ar ==='string') {
return 0;
} else {
return ar.length;
}
}
You wrote 'Number' and 'String' instead of 'number' and 'string'. When checking the types, its all in lower case!
Joseph Potts
11,187 PointsHello!
Post the code you're using for us to be able to help you. From what I see it, if you just pass an array variable as an argument to a function (that takes a parameter), it will hold that array value in the parameter variable. So for example if the main variable was john1 and the parameter was john2 in a join() function, you'd do this:
Call join() with john1 as an argument so join(john1). This will make john2 a replica of john1 i.e. an array. Just use john2(1) or any other value to access the array.
Thanks!
Robert Marczak
12,358 Pointsthis is my challange
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.
and this is my code
<script>
function arrayCounter(array){
if(typeof array==='undefined' || typeof array==='Number' || typeof array ==='String'){
return 0;
}
return array.length;
}
arrayCounter();
</script>
Robert Marczak
12,358 Points<script>
function arrayCounter(array){
if(typeof array==='undefined' || typeof array==='Number' || typeof array ==='String'){
return 0;
}
return array.length;
}
arrayCounter();
</script>
Robert Marczak
12,358 Pointsit worked, thanks for your help.