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

jQuery Utility Method Quiz

Hi Guys,

I'm kind of stuck in the first question

Call 'map' on the inputs with the class 'required' and return each of their values and store it in a variable named 'values'.

This is the code I'm using

var $required = $(".required");
var values = $required.map(function(){ 
  return $(this).val() == "";
}); 
return $.inArray(true, values) != -1;

But I keep getting the error

Bummer! You haven't set the variable 'values'

Any ideas?

5 Answers

Thanks Nick!

Gregory, I tried the same code as you before but that's checking for empty values and not all values

The actual answer for 1 of 2 was

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

And the 2 of 2 was adding

$.inArray("Andrew", values);
Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

This line needs changing return $.inArray(true, values) != -1;

Only $.inArray(true, values); is required. You can't use return outside a function. So a syntax error occurs and the script isn't parsed correctly and cannot see values.

Thanks Andrew!

Now if I change the code to this

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

I even tried changin to this

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

But now I get 'The values aren't what we're expecting. Please try again.'

Your talking about task 1 of 2 correct?. If that's the case line 3 (your return) .val call doesn't need equals to blank. You just want it to store the value.

var $required = $(".required");
var values = $required.map(function(){
    return $(this).val();
});
Gregory Serfaty
Gregory Serfaty
37,140 Points

The answer is

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