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
Trevor Wood
17,828 PointsStuck on a Jquery Code Challenge
I'm stuck on the second part of the challenge. Here's the link
Objective: Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'.
My answer:
function isValidEmail(email){
return email.indexOf("@") != -1;
}
var $required = $(".required");
var $var = new array();
function requiredValue(){
$required.each(function(){
$var.push($(this).val());
})
}
Can anyone tell me what I'm doing wrong? or what I'm not doing right?
1 Answer
Adam Sackfield
Courses Plus Student 19,663 PointsAfter you declare the function you need to create a new array, then using jQuery selector you need to target all the inputs with the required class
var requiredValues = function() {
var myArray = new Array();
$('.required').each(function(){
myArray.push($(this).val());
});
return myArray;
}
Trevor Wood
17,828 PointsTrevor Wood
17,828 PointsThanks Adam! I had been stuck on that for a while.
Adam Sackfield
Courses Plus Student 19,663 PointsAdam Sackfield
Courses Plus Student 19,663 PointsNo problem click best answer to mark as solved (its the tick next to up vote). Others will be aided then too. Trevor Wood
Trevor Wood
17,828 PointsTrevor Wood
17,828 PointsI was going to ask about that. Sometimes it doesn't appear on my screen. Right now it's not displaying "best answer" or the two arrows that are normally beside it. Is this an error? or do I need to activate it or something?