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 trialJoshua Moore
8,013 PointsJQuery Form Validation Challenge 2
Really struggling with this. Not sure if I'm close or not. It asks "Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'." This is one thing I tried:
var $required = $(".required");
function requiredValues() {
var values = new Array();
$required.each().val(function() {
return values.push();
});
};
3 Answers
Jay Goettelmann
1,368 PointsHey Joshua,
Haven't taken the course, but maybe:
function requiredValues(){
var values = [];
$("input.required").each(function(){
values.push( $(this).val() );
});
return values;
}
Joshua Moore
8,013 PointsIt worked. Thanks :) I really want to learn this stuff but sometimes I just find it difficult to comprehend...
Jay Goettelmann
1,368 PointsNo problem! Glad to help.
Hunter Stewart
11,515 PointsJoshua Moore, even if you've moved on, I think you will really benefit from the .each documentation, to help you totally grok this Code Challenge! It seems that's where you first run into trouble in your code at line 4.
Joshua Moore
8,013 PointsThanks for the tip. I'll look into that. :)
James Barnett
39,199 PointsJames Barnett
39,199 PointsJay Goettelmann - Remember our goal here on the forum is give help not answers, next time try giving an explanation and/or a hint instead. Rather than just giving someone the answer, I'd suggest you take a look at their code and try and figure out where they went wrong and give them a hint to point them in the right direction.
Jay Goettelmann
1,368 PointsJay Goettelmann
1,368 PointsNoted.
Thanks James.