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

JavaScript

Code 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

var 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
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Remove 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
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Here's it split in to a more logical order:

  1. Create a variable called values
  2. Using jQuery select .required
  3. Call map on it
  4. 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.

I 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."

Oops nevermind. I got it. I wasn't returning anything before.

Thanks Mr. Chalkley.

Thanks Andrew!