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

Form Validation and Manipulation - Checking Values

Man I am so crap at Javascript it's not even funny, lol.

I'm doing the above quiz, found here : http://teamtreehouse.com/library/checking-values ( course found here: http://teamtreehouse.com/library/websites/build-an-interactive-website/form-validation-and-manipulation )

I've got past the first task of three, fine.

I'm onto the second task and I'm getting a null result.

My code is as follows : http://codepen.io/anon/pen/svEfk

Now, I'm struggling with it already, had to re-go over the videos from the start in this section, and I downloaded the files, and notated everything (in my own way) to understand.

So I can't understand how or why the code I've provided is null sad panda face

Any help would be much appreciated :-)

15 Answers

I also have been stuck on this step for awhile and haven't been able to figure it out. I know this doesn't answer your question, but maybe you'll feel better knowing you're not the only out there who is stuck.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Caroline and Jarren,

Task 2 is just asking for the values to be returned and isn't looking for blanks. You therefore don't require == "" or return the sorted and popped value in this task.

This task is testing if you can put the values (using the val() method, in to an array).

Task 3 will be looking for blanks.

Regards Andrew

Hello Andrew,

Thanks for responding. Here is my code. I feel like I'm on the right track, but I just don't understand what to write in order to return. If you could help me along the path I would be very appreciative.

http://codepen.io/jarrenb/pen/HnBqi

Thanks, Jarren

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

For yours Jarren, the each() method takes an anonymous function, within it you need to select this, like $(this) then you can call val() and push that on to an array.

function requiredValues() {
     //Declare array here
     $(".required").each(
          //Put function in here and push values on to array
      );
     //Return array here
}

Hope this helps.

After 5 more tries and rereading your words a few times, I finally got it! Thanks for you help Andrew!

Oh crap! I've run into trouble in task 3.

Here's what I have so far.

http://codepen.io/jarrenb/pen/HnBqi

Sorry to be a bother.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Almost there, you need to return blanks and followed by the same technique in the previous video :)

OH MAN! Thanks for the help. I gave up too easy. Those were tough ones. Thanks for not just giving me the answers out right and thanks for being patient.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

No worries! Keep up the good work.

I promise if you keep on trying and persevering, tweaking and testing true understanding eventually comes.

everytime i put

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

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

it keeps saying "It looks like Task 1 is no longer passing." What can I do to fix this?

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Just before the return It looks like you have an extra ); This is causing a syntax error tripping up Task 1.

I know this is an old post but the comments really helped me with the code challenge. Finding JavaScript almost impossible at times but I think am gonna download all the videos to try to fully understand this.

If anyone is finding JavaScript easier than me please can you throw some tips.

Thanks again.

can not get this for the life of me!!!

Bummer There is something wrong with your code in your 'containsBlanks' function.

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

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

function containsBlanks(){
  var blanks = new Array();
  $(".required").each(function(){
    blanks.push($(this).val() == "");
  });
  return true
}
Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

There is something wrong with your code. You're returning true all the time. :)

Would love to get some help on task 2 of this section. I've gone through the discussion and still can't seem to figure out what is wrong with my code. I am getting an error that task 1 is no longer passing. Help!!!

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

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

never mind, sometimes spell check can be your best debugger :)