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
Pedro Pinto
3,798 PointsForm 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
Treehouse Guest TeacherHi Pedro,
Can you show us your code? We can then point you in the right direction.
Regards Andrew
James Barnett
39,199 PointsWhenever 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
Pedro Pinto
3,798 PointsHi, this is the code that Im using:
function requiredValues() {
return $(".required").val();
};
Andrew Chalkley
Treehouse Guest TeacherHi 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
};
Pedro Pinto
3,798 PointsThanks 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
Treehouse Guest TeacherHi 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
gabriel benatov
Courses Plus Student 3,317 PointsAndrew Chalkley
Treehouse Guest TeacherHi 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
gabriel benatov
Courses Plus Student 3,317 PointsThanks alot I made it almost gave up in saying: "coding is not for me", "I am not the coding person"
Andrew Chalkley
Treehouse Guest TeacherKeep at it Gabriel!
Sometimes we don't realize how close we are to the answer. We're always here to help.