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: jQuery Form Validation - jQuery Utility methods - Challenge 1 of 2
Task: Call 'map' on the inputs with the class 'required' and return each of their values and store it in a variable named 'values'.
My "Failed" code:
$(".required").map(function () {
return($ var ("values") });
This section seemed to be very fast-paced and had a ton of blanks...
6 Answers
Guled A.
10,605 PointsSo the question says to call map with the class required and store them in the variable values.
First we start off by declaring the variable name 'values', then we proceed to call the map function on the class required. Inside this function we return each of the values. We use the this method to return whatever value there is.
var values = $(".required").map(function(){
return $(this).val()
});
Hope this helped. :)
Kyle Brooks
6,753 Pointsoh snap. I totally flipped that in my mind. Thanks for the help!!
Maybe you can help with #2 as well...
Question is: Using the 'inArray' method check if the array contains the string 'Andrew'
I tried this...
var values = $(".required").map(function(){
return $(this).val()
});
return $.inArray(true, Andrew) != -1;
Message: Task 1 is no longer passing...
Guled A.
10,605 PointsThe question asks to call the inArray method. Just remove 'return' from the line:
return $.inArray(true, Andrew) != -1;
And you should be good to go. Hope this helped. :)
Giovanni CELESTE
20,961 PointsHi Kyle :),
Thanks for the link and title, I appreciate it ^^.
EDIT: my answer was no longer needed.
When you do check "if" something...you would have a hint of what you should write.
Here, your return doesn't check "if". You may wrap your return in a if condition. You can do that by now, so rock it! :)
Giovanni CELESTE
20,961 PointsEdited my previous answer, took too much time to answer the first, and Guled had a better answer anyway.
Kyle Brooks
6,753 PointsGiovanni and Guled, Thanks to both of you for the help here!!
After adapting the code to what Guled suggested in task 2, I still got a "Bummer! You need to call 'inArray' in jQuery." I thought I did that when I typed "$.inArray"
$.inArray(true, Andrew) != -1;
István Turupoli
11,950 PointsI may be late with this, but I too had a little trouble with this, but finally got it right.
So, the problem was, with the inArray call. You need to pass the the searched term "Andrew" as the first value, and than the name of the array as the second. Like this:
$.inArray( "Andrew", values) != -1;
In the and the jQuery documentation was the most helpful source a could find: example link
Hope this helps
István Turupoli
11,950 PointsIgnore this - a was just trying to edit my previous post.