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
Adam Porter
12,362 PointsCode Challenge: jQuery Utility Methods
Struggling with this problem altogether:
Call 'map' on the inputs with the class 'required' and return each of their values and store it in a variable named 'values'. Any insight on where to start?
5 Answers
Chase Lee
29,275 Pointsvar values = $(".required").map(function(){ return $(this).val() ==""; })
I have tried this but it says:"The values aren't what we're expecting. Please try again."
Andrew Chalkley
Treehouse Guest TeacherRemove the =="". The =="" is testing the values in each required field with the empty string, all we want is the values themselves. The .val() method returns the value in an input. That's all that is needed for this step.
Andrew Chalkley
Treehouse Guest TeacherHere's it split in to a more logical order:
- Create a variable called values
- Using jQuery select
.required - Call
mapon it - In the map call write an anonymous function and return
$(this).val()i.e. the value of the required field.
Hope this helps. If not paste in where you get to and we'll take it from there.
jjr
14,539 PointsI don't understand what I'm doing wrong. I followed your directions and got this:
var values = $(".required").map(function(){$(this).val()});
And when I submit, it says "Bummer! The values aren't what we're expecting. Please try again."
jjr
14,539 PointsOops nevermind. I got it. I wasn't returning anything before.
Chase Lee
29,275 PointsThanks Mr. Chalkley.
Rob Thomas
Courses Plus Student 7,601 PointsThanks Andrew!