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 Build an Interactive Website Form Validation and Manipulation Checking Values

Jquery Help Needed Whats Wrong with this Code?

Create a method called 'containsBlanks' that returns true if any inputs with class 'required' has an empty string in, false if not.

var $required = $(".required");
function containsBlanks(){
  var blanks = new Array();
  $required.each(function(){
    blanks.push($(this).val()) != "");
  });
return blanks.indexOf(true) != -1;

1 Answer

Hi Steve,

You didn't mention if you were having a syntax error or logic error but I suspect you may be having both.

If you take a look at this line:

blanks.push($(this).val()) != "");

You have an extra right parenthesis. Also, I don't see a closing brace for the containsBlanks function but you may have left that off when pasting.

You also may have a logic error.

It looks like you're trying to push a true value onto the array if the field isn't empty. I would recommend that you push a true value onto the array if it is an empty field.

A true entry in the blanks array should indicate that the field was empty.

Let me know if you need more clarification.