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

Code Challenge: Form Validation - jQuery Utility Methods - Challenge 2 of 2

Task: Using the 'inArray' method check if the array contains the string 'Andrew'

URL: http://teamtreehouse.com/library/build-an-interactive-website/form-validation-and-manipulation/jquery-utility-methods

I tried answering this question multiple different ways over the past two days. The first code that I ran was:

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

With some help from the forum, I then adjusted it to show without the 'return' :

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

Still didn't work...can anyone help?

5 Answers

Hi Kyle :),

For the challenge, the array is referencing to the previous challenge. So your array is values

You should have a form like this:

$.inArray.(whatYouAreLookingFor, theArray);

Check the documentation about it here

I followed these guidelines and I'm still getting the following error, "Bummer! You need to call 'inArray' on jQuery."

Can somewhere please tell me where I went wrong?

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

jQuery.inArray(Andrew, values) != -1; '''

Did you try "Andrew" in quotes?

Thank you, Giovanni. That was completely right. I should have known that the argument for Andrew needed to be passed as a string. It's these little things that make programming both frustrating and fun!

Thanks again.

You're welcome, and I agree :), frustrating when it doesn't work (and you can't figure out what you did wrong), and fun when you finally find you the answer (but a small bitter taste for wasting that much time for a so simple mistake :D). Well, that's programming for you, and we love it (who said masochist?!).

got it figured out. thanks for the help! was missing jquery from my method!

Actually no, that's not what was wrong, I think. What was you answer in the end? It works and that's great, but it's better to understand it perfectly.

Hey...no, that was what was wrong. It worked! Thanks for the help!

I followed these guidelines and I'm still getting the following error, "Bummer! You need to call 'inArray' on jQuery."

Can somewhere please tell me where I went wrong?

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

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

looks good apart from Andrew needs to be in quotes...