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!

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


JQuery 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
Jay Goettelmann
1,368 Points

Hey Joshua,

Haven't taken the course, but maybe:

function requiredValues(){
    var values = [];
        values.push( $(this).val() );
    return values;
James Barnett
James Barnett
39,199 Points

Jay 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.

It worked. Thanks :) I really want to learn this stuff but sometimes I just find it difficult to comprehend...

Jay Goettelmann
Jay Goettelmann
1,368 Points

No problem! Glad to help.

Hunter Stewart
Hunter Stewart
11,515 Points

Joshua 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.

Thanks for the tip. I'll look into that. :)