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
Kyle Brooks
6,753 PointsCode Challenge: Form Validation - jQuery Utility Methods - Challenge 2 of 2
Task: Using the 'inArray' method check if the array contains the string 'Andrew'
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
Giovanni CELESTE
20,961 PointsHi 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
Giovanni CELESTE
20,961 PointsDid you try "Andrew" in quotes?
eyeloveotters
15,097 PointsThank 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.
Giovanni CELESTE
20,961 PointsYou'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?!).
Kyle Brooks
6,753 Pointsgot it figured out. thanks for the help! was missing jquery from my method!
Giovanni CELESTE
20,961 PointsActually 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.
Kyle Brooks
6,753 PointsHey...no, that was what was wrong. It worked! Thanks for the help!
eyeloveotters
15,097 PointsI 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;
Ben Pease
7,702 Pointslooks good apart from Andrew needs to be in quotes...
eyeloveotters
15,097 Pointseyeloveotters
15,097 PointsI 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; '''