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 trialMayur Pande
Courses Plus Student 11,711 PointsMy code works so far but...
it when I clear the password form field, then hint stays there, I thought this line is supposed to make it hide;
//1) Hide hints
$("form span").hide();
Here is my full app.js
//Problem: Hints are shown even form is valid
//Solution: Hide and show them at appropriate times
var $password = $('#password');
var $confirmPassword = $("#confirm_password");
//1) Hide hints
$("form span").hide();
function passwordEvent() {
//return val - which is a string - then check if length is greater than 8
//2) Find out if password is valid
if($password.val().length > 8){
//2.1) Hide hint if valid
$password.next().hide();
}else{
//2.2) else show hint
$password.next().show();
}
}
function confirmPasswordEvent(){
//3.1) Find out if password and confirmation match
if($password.val() === $confirmPassword.val()){
//3.2) Hide hint if match
$confirmPassword.next().hide();
}else{
//3.3) else show hint
$confirmPassword.next().show();
}
}
//When event happens on password input - events on particular input
$password.focus(passwordEvent).keyup(passwordEvent).focus(confirmPasswordEvent).keyup(confirmPasswordEvent);
//3) When event happens on confirmation input
$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent);
Raymer Ramos
7,683 PointsRaymer Ramos
7,683 PointsHey Mayur Pande
that line of code will only hide it at the beginning of the program, the reason it stays after you clear the password field is because the event handler keyup is being called on it when you release the backspace key, so since the empty field length is less than 8 the hint stays visible