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

I'm having problems to solve the task 2/3. Can anyone show which is the right code?

Thanks

10 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Pedro,

Can you show us your code? We can then point you in the right direction.

Regards Andrew

Whenever you post about an issue with a code challenge 2 things are very helpful:

  • A link to the code challenge you are having issues with
  • A "working" example using codepen.io

Hi, this is the code that Im using:

function requiredValues() {
    return $(".required").val();
};

Task 2 of http://teamtreehouse.com/library/checking-values

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Pedro,

The task is looking for an array as the value.

Here's an outline of what you need to do and maybe this will help.

function requiredValues() {
  //Define an array
  //Cycle over $(".required") with the each method
     //Within an anonymous function return the value of the current element $(this)
 //return the array at the end of the method
};

Thanks for the answer. I've tried this code but it doesn't work:

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

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

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Pedro,

The task is looking for an array of values not blanks.

You also need to push() the values in the each() method.

Regards,

Andrew

3/3

cant get it right:

http://codepen.io/Gbenatov/pen/cAosh

please guide me.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Gabriel

You're almost there. You're using indexOf so if there is a blank we're looking for the true value. It will return an index of where the true is. So if the indexOf is not -1 then it contains a blank.

    return blanks.indexOf(true) != -1;

The only issue with indexOf is that it's not cross browser compatible. You can check the video before to see how the blanks.sort().pop() algorithm works. Also indexOf has a capital O :)

Regards

Andrew

Thanks alot I made it almost gave up in saying: "coding is not for me", "I am not the coding person"

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Keep at it Gabriel!

Sometimes we don't realize how close we are to the answer. We're always here to help.