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

JavaScript

Jquery 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:

http://teamtreehouse.com/library/build-an-interactive-website/form-validation-and-manipulation/checking-values

If anybody could help it would be much appriciated!

Thanks,

Adam

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Adam;

I would point you to the discussion on this challenge task here, Mr. Chalkley has some good input in the discussion on this.

Ken

Thankyou very much! Your a massive help!

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Adam;

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

Had a rookie moment thanks for that!

Hey 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; } }

link: http://teamtreehouse.com/library/build-an-interactive-website/form-validation-and-manipulation/checking-values

Adam