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
Andrej Kirin
18,967 PointsStucked
Hello!
I just can't solve task 2 of this challenge; http://teamtreehouse.com/library/build-an-interactive-website/form-validation-and-manipulation/checking-values
I've been trying hard, but I'm not clear what should I do. This is one of my last codes:
function isValidEmail(email){ return email.indexOf("@") != -1; }; var $required = $(".required"); function requiredValues(){ var array = new Array(); $required.each(function(){ array.push($(this).val() == ""); }); return array.sort().pop();
If there is anyone who is able to provide solution or advice I would be grateful.
Thanks
2 Answers

Mike Bronner
16,395 PointsYour code:
var $required = $(".required");
function requiredValues()
{
var array = new Array();
$required.each(function()
{
array.push($(this).val() == "");
});
return array.sort().pop();
The differences I'm noticing is that your code is not adding the value of the field, but instead a boolean that denotes if it was empty or not. I don't believe that's what is asked for. Also, your result is sorted, and you have removed the last element from the array, that is also not being asked for. I'm assuming the the missing closing brace is just a copy error, but that you have it in your code. Another thing to check is that you are looking at everything with a class of required
, it only wants input fields with the class of required. Also, you have a $-sign before your required object ... not necessary in JavaScript.
I updated your function with the above corrections, and it worked. :)

Andrej Kirin
18,967 PointsThanks, I'll try working it out later and will let you know.
Mike Bronner
16,395 PointsMike Bronner
16,395 PointsHang on ... ran into a snag here ... will update in a sec.
Mike Bronner
16,395 PointsMike Bronner
16,395 PointsOK, answer updated.