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

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