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
Daniele Manca
Courses Plus Student 7,548 PointsHelp with "Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'."
Hi all,
Could someone help with this function please?
I am kinda stuck,
:(
5 Answers
Andrew Chalkley
Treehouse Guest TeacherHey Daniele Manca
The questions is asking for the values which is val() not val() == "". If that's what you're doing :)
Regards
Andrew
Daniele Manca
Courses Plus Student 7,548 Points@Josh, I do agree with you pal, because i felt exactly the same way you described it, oh well...
Sander de Wijs
Courses Plus Student 22,267 PointsHi Andrew,
Is it possible to use ``` var myArray = new Array
instead?
Andrew Chalkley
Treehouse Guest TeacherYou'll need () at the end but yeah :)
Josh Flowers
7,010 PointsI'm lost. It seems like I'm trying what you suggest, but then I get "task 1 is no longer passing"
function isValidEmail(email){
return email.indexOf("@") != -1;
}
function requiredValues() {
var myArray = [];
$(".required").each(function() {
myArray.push($(this).val();
});
return myArray;
}
Josh Flowers
7,010 PointsNever mind, I noticed I was missing a bracket.
Andrew Chalkley
Treehouse Guest TeacherYou'll have a syntax error on this line:
myArray.push($(this).val();
You're missing a )
Josh Flowers
7,010 PointsThanks, but luckily I caught it before you posted! lol
Andrew Chalkley
Treehouse Guest TeacherNo worries :) A second pair of eyes is always good to have :)
Josh Flowers
7,010 PointsHave you found that these 3 code tasks cause quite the bit of confusion? I didn't find the material overly difficult in the video, but the way the tasks were structured really threw me off.
I guess what I'm trying to say is that (mostly for task 2 and 3) I wasn't really sure what I was being asked to do.
I dunno, maybe it's just me.
Daniele Manca
Courses Plus Student 7,548 PointsDaniele Manca
Courses Plus Student 7,548 PointsThanks Andrew, think I am being a little dumb in here, I've been trying to use different variations of the below code, without any success:
function requiredValues(val) { return val.addClass(".required"); }
Dani
Andrew Chalkley
Treehouse Guest TeacherAndrew Chalkley
Treehouse Guest TeacherNo worries Daniele Manca!
There are fields with the class "required".
So to select them you'd use
$(".required").To do what the question is asking you'd need to do this.
Hopefully this pseudo-code above will point you in the right direction.
Daniele Manca
Courses Plus Student 7,548 PointsDaniele Manca
Courses Plus Student 7,548 PointsHey Andrew, thanks again,
But I am still stuck, I do get the concept now, but I am unable to make it work exactly...
This is the code I am now using:
Andrew Chalkley
Treehouse Guest TeacherAndrew Chalkley
Treehouse Guest TeacherYou're almost there...
Sander de Wijs
Courses Plus Student 22,267 PointsSander de Wijs
Courses Plus Student 22,267 PointsHi Andrew,
Is it possible to use ''' var myArray = new Array; ''' instead of ''' var myArray = [] '''