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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Daniel Sarmiento](https://uploads.teamtreehouse.com/production/profile-photos/8006352/micro_68610347_2954967644533026_2750962794022043648_n__1_.jpg)
Daniel Sarmiento
10,265 PointsPassword validation and password confirmation are not working after arePasswordsMatching() and isPasswordValid() applied
I was following along in workspaces and in min 3:30 Andrew showed the form working properly, but I haven't been able to make it work and I think I have the same code as his!
If you can see what's wrong with my code please tell me.
// problem: hints are shown even when form is valid
// solution: hide and show them at appopiate times
var $password = $("#password");
var $confirmPassword = $("#confirm_password");
// hide hints
$("form span").hide();
function isPasswordValid() {
return $password.val().length > 8;
}
function arePasswordsMatching() {
return $password.val() === $confirmPassword.val();
}
function passwordEvent() {
// find out if the password is valid
if(isPasswordValid()){
// hide hint if valid
$password.next().hide();
} else {
// else show hint
$password.next().show();
}
}
function confirmPasswordEvent() {
// find out if password and confirmation match
if(arePasswordsMatching()) {
// hide hint if match
$confirmPassword.next().hide();
} else {
// else show the hint
$confirmPassword.next().show();
}
}
// when event happens on password input
$password.focus(passwordEvent()).keyup(passwordEvent()).focus(confirmPasswordEvent()).keyup(confirmPasswordEvent());
// when event happens on confirmation input
$confirmPassword.focus(confirmPasswordEvent()).keyup(confirmPasswordEvent());
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsCongratulations on resolving your own issue.
![Daniel Sarmiento](https://uploads.teamtreehouse.com/production/profile-photos/8006352/micro_68610347_2954967644533026_2750962794022043648_n__1_.jpg)
Daniel Sarmiento
10,265 PointsThanks man.
Daniel Sarmiento
10,265 PointsDaniel Sarmiento
10,265 PointsI've just solved this. I was calling functions inside methods "keyup" and "focus" with "()" at the end.
The fix
Silly syntax error but got the scratching my head for a while.