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

Can't understand what this task want from me...

var qwer = [333, undefined, "alex"];
function arrayCounter(qwerItem) {
   if (typeof qwer[qwerItem] !== "undefined" || typeof qwer[qwerItem] == undefined || typeof qwer[qwerItem] == "object") {
       return qwer.length;
    } else {
       return 0;
    }
}

1 Answer

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Aleksandr,

The challenge wants you to return 0 if the parameter value passed in is a string, number or is undefined.

The first issue is you are checking an element in the array, but you should only be checking the type of the parameter passed in.

In your function you are checking for 'object' is a type to return 0 for. Instead of checking that the type is not object, check that the type is not number.

Also, you only need to create the function itself. You can remove your array above your function.

I hope this helps.

thanks for help.