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 Form Validation Code Challenge Task 3

I can't figure this one out for some reason. It is asking me to Create a method called 'containsBlanks' that returns true if any inputs with class 'required' has an empty string in, false if not.

So here is the code I haven now

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

var $required = $(".required");
function requiredValues () {
inputArray = new Array();
$required.each(function () {
 inputArray.push($(this).val());
 });
 return inputArray;
   };

   function containsBlanks () {
    if(requiredValues().val() == "")
      return true;
    else 
      return false;

    };

1 Answer

Hello Casey,

You wouldn't be the first to have difficulties with this one I know I got held up trying to solve it too. Even though there is lots of ways to solve this problem this is what worked for me:

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

There was also another student by the same name that asked this question before and Andrew was kind to respond to his questions. Check it out and if you have any more questions let me know.

Code challenge: Checking values

This is exactly the solution that I just came up with before I read this post. The reason it took me this long to think of it is because I was pretty much rewriting the last function with a couple additions.

Thanks for the help though!!