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
Adam Duffield
30,494 PointsJquery Build an interactive site task 2/3
Hi, I'm having difficulties with this task, I'm unsure whether it's explained very well or whether it's just me.
Task is:
Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'.
My Code:
var requiredValues(){
var myarray = new array();
$(".required").each(function(){
myarray.push($(this).val());
}
};
The task URL:
If anybody could help it would be much appriciated!
Thanks,
Adam
3 Answers
Ken Alger
Treehouse TeacherAdam;
I would point you to the discussion on this challenge task here, Mr. Chalkley has some good input in the discussion on this.
Ken
Ken Alger
Treehouse TeacherAdam;
Your code looks great, you just aren't returning the array. You need to add return myArray; like so:
var requiredValues = function()
{
var myArray = new Array();
$('.required').each(function()
{
myArray.push($(this).val());
});
return myArray;
}
Keep up the great work.
Ken
Adam Duffield
30,494 PointsHad a rookie moment thanks for that!
Adam Duffield
30,494 PointsHey Ken cheers for that one! Though now i'm having issues with the task after,
task: Create a method called 'containsBlanks' that returns true if any inputs with class 'required' has an empty string in, false if not.
mycode: var containsBlanks = new function(){ if $(".required").val() == ""){ return true; } else { return false; } }
Adam
Adam Duffield
30,494 PointsAdam Duffield
30,494 PointsThankyou very much! Your a massive help!