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 Build an Interactive Website Form Validation and Manipulation jQuery Utility Methods

Robert Bullen
Robert Bullen
8,022 Points

Can't get this to work - Map Function from validation

I've looked at everything else, and thought I had this but it keeps saying the same thing. "You haven't set the variable 'values'". But I have: this is the code I'm submitting -

var required = $(".required");

function requiredValues(){

var values = required.map(function(){return $(this).val();});

}

1 Answer

What you've written could pass the code test if you made values a global variable and you also called your function so that the map code can be executed:

var required = $(".required");
var values;

function requiredValues(){

values = required.map(function(){return $(this).val();});

}

requiredValues();

But you're writing more than what is required for task 1. You only need the line that's calling the map function.
var values = required.map(function(){return $(this).val();});

The directions would have been more specific if they wanted you to put it in a function.