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
Checking values JQUERY
Been hanging around this problem for 2 days now.
"Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'."
tried -
$required = $(".required");
function requireValues(){
var values = new Array();
$required.each(function(){
values.push(this).val(); });
return values; }
what am I doing wrong?
3 Answers
J.T. Gralka
20,126 PointsTake a look at the point in your code where you call "this":
values.push(this).val();
I think you're trying to push the value of "this" into the array; the code as is doesn't work because you're trying to push the entire element into the array and then return a value, and your syntax is a bit off. I think you want to push the value of the current field into the array.
My suggestion would be to rewatch the video to relearn how to use $.each() and $(this).
Feel free to reply if this isn't making any sense to you; also, don't hesitate to get in touch with the support team at help@teamtreehouse.com.
Best,
J.T.
ecp
838 PointsYou ROCK J.T :)
ecp
838 PointsYou ROCK J.T. :)