Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.