Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

jquery code challenge

I am stuck on this can anyone help? Using the 'inArray' method check if the array contains the string 'Andrew'

My answer is,

 return $.inArray(true, Andrew) != -1; 

When I put my answer in it does not come up with a Bummer it sends me back to previous task.

Kind regards, Neil

2 Answers

Stone Preston
Stone Preston
42,016 Points

Andrew needs to be a string. Where you have (true, Andrew), andrew is not a string so you are getting an error because the inArray method doesnt recognize the argument.

Its been a while since ive worked with jQuery so I could be wrong.

Hi Stone,

How do I write Andrew as a string..?

Regards,

Neil

Paul Ozag
Paul Ozag
11,369 Points

i am not sure but i think one of the arguments in the $.inArray method is the name of the array. cant remember but i think it's the first argument and the string 'Andrew' is the second.

How do I write Andrew as a string...?

Paul Ozag
Paul Ozag
11,369 Points

put either single or double quotes around it : 'Andrew' or "Andrew"

Hi Paul,

My answer is this their are 3 blanks the 1st is 'Andrew' this is my code I have tried.

return $.inArray(true, 'Andrew') != -1; I have also tried this next code.

return $.inArray(true, blanks) 'Andrew' != -1; I have also tried this next code. return $.inArray(true, blanks 'Andrew') != -1;

Can you help please...?

Neil

Paul Ozag
Paul Ozag
11,369 Points

try this: return $.inArray (blanks, 'Andrew') != -1;

HI Paul,

I have tried this still no joy....I will ask the help team if they can put me intouch with Andrew Chalkey.

Unless you have any more idea's..?

Regards,

Neil

Hi Paul,

Finally got the correct code this is it:

var values = $(".required").map(function(){ return $(this).val() }); $.inArray("Andrew", values);

I hope this makes sense to you.

Neil