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
Gil David
8,811 PointsCode challenge Checking values
I'm trying to pass the third part of this challenge and tried out this code:
function containsBlanks() {
var inputs = $(".required");
inputs.each(function(){
if($(this).val() == "") return true;
});
return false;
}
and BTW how do I add an image to a message here?
2 Answers
Jacob Pojar
2,316 PointsHi!
I'm learning the exact same thing!
I found that you need to check the true false thing at the top level for "containsBlanks", plus you need to use an array. I remember a blank string is a "falsey"
function containsBlanks(){
var blanks = new Array();
$(".required").each(function(){
blanks.push( $(this).val() );
});
if( blanks.indexOf("") != -1)
return true;
else
return false;
}
Gil David
8,811 PointsThanks! to be honest I already solved to challenge using this code but I still don't understand why the code I have written before does'nt work. It seems to be that my original code was more elegant...