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

Jacob Roman
22,640 PointsChecking Values Code Challenge
I have been trying to figure out what I am doing wrong for the Forms and Validation - Checking Values Video.
Below is the code I have input and it says that something is wrong with my requiredValues function. I am not that great with Javascript. Any help would be great so I can comeplete this quiz.
Thanks in advanced.
var $required = $(".required");
function requiredValues(){
var blanks = new Array();
$required.each(function(){
blanks.push($(this).val() == "");
});
return blanks.sort().pop();
}
function isValidEmail(email) {
return email.indexOf("@") != -1;
}
4 Answers

Joseph Siddiq
Courses Plus Student 7,133 PointsHey Jacob - The challenge (task 2 of 3, just to make sure) is looking for narrower response than the functions described in the video, I was doing the same as above but the below worked out for me. Rather than testing the returned value, all you need to do is just return an array with all the values of the inputs.
The below worked for me, 'values' represents an array populated by the values of each of the inputs with the class required. Then you just return the array.
Let me know if I'm overlooking something.
var requiredValues = function(){
var values = new Array();
$(".required").each(function(){
values.push($(this).val());
});
return values;
};

Jacob Roman
22,640 PointsThanks for the response. I actually just got my answer from this post right before you posted. haha.

Jessica Barnett
8,028 PointsThanks for this post! I was having a very similar problem and you helped me out too. yay.

Armand Ramirez
4,016 PointsInteresting, I was having a similar problem.
This code wasn't passing:
function requiredValues(){
var tArray = new Array();
$(".required input").each(function(){
tArray.push($(this).val());
})
return tArray;
}
I changed the selector to $('.required') and the code passed, even though $('.required input') is actually selecting the same element, no?