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
Diana Moura
8,629 PointsCode problem JQuery - password form -perfect
Hi! I'm having problems with debugging this code for the Jquery Creating a password form - perfect. The button is not working when password is inserted and the hint for the password longer than 8 characters keeps appearing even when the password is longer.
Can anyone help? Thank you in advance!
//hints shown always
//solution hide hints and show at apropriate times
var $password = $("#password");
var $confirmPassword = $("#confirm_password");
//hide hints
$("form span").hide();
function isPasswordValid() {
return $password.val().lenght > 8;
}
function arePasswordsMatching() {
return $password.val() === $confirmPassword.val();
}
function canSubmit() {
return isPasswordValid() && arePasswordsMatching();
}
function passwordEvent() {
//find out if password is valid
if(isPasswordValid()) {
//hide hint if valid
$password.next().hide();
} else {
//else show hint
$password.next().show();
}
}
function confirmPasswordEvent() {
if(arePasswordsMatching()) {
//hide hint if matched
$confirmPassword.next().hide();
} else {
$confirmPassword.next().show();
//else show hint
}
}
function enableSubmitEvent() {
$("#submit").prop("disabled", !canSubmit());
}
//when event happens on password input
$password.focus(passwordEvent).keyup(passwordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);
$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);
enableSubmitEvent();
//when event happens on confirmation input
//find out if password and confirmation match
2 Answers
Kevin Kenger
32,834 PointsHey Diana,
It seems like you just have a simple typo in your isPasswordValid function. You just misspelled the word length! I think once you fix that you should be good to go!
Diana Moura
8,629 PointsThank you so much Kevin it works fine now :D I had been searching for the bug for hours and it ended up being really simple. Thanks again :)
Kevin Kenger
32,834 PointsMy pleasure! :)
Yorick Toma
742 PointsYorick Toma
742 PointsCould you setup a JSfiddle ? or at least markup the code ^^ ?
Thanks !