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

HTML Build an Interactive Website Form Validation and Manipulation Checking Values

Create a method called 'containsBlanks'

Need a second set of eyes, I don't see whats wrong here:

function isValidEmail(email){
    return email.indexOf('@') != -1;
}

function requiredValues(){
  var values = [];
  $('.required').each(function(){
    values.push($(this).val());
  });
  return values;
}

function containsBlanks(){
    var results = requiredValues();
  var blanks = new Array();
  results.each(function(){
    blanks.push($(this) == "");
  });
    return blanks.sort().pop();
}

2 Answers

Adrianne Geyer
Adrianne Geyer
7,180 Points

It looks like you are attempting to call in the requiredValues function from the previous challenge when you do not need it for part 3. To complete this challenge you need to do the following:

(1). declare a variable for your array (2). use the class 'required' with the each() function to include all input fields (3). push() all empty strings into your array (4). sort() and pop() the array so all the true & false values are grouped together

function containsBlanks() {
  var emptyFields = new Array();
  $('.required').each(function() {
    emptyFields.push($(this).val() == "");
  });
  return emptyFields.sort().pop();
}

Let's just say you can answer part 3 with 1 line of code by using the function you coded up in part 2.