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 jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 1

My hints won't hide at all

What could be going wrong with this? Any help would be appreciated.

//Problem:  Hints are shown even when form is valid
//Solution:  Hide and show them at appropriate times

//Hide Hints
$("form span").hide();

function passwordEvent() {
  //Find out if the password is valid
  if($(this).val().length > 8) {
    //Hide hint if valid
    $(this).next().hide();
  } else {
    //else show hint
    $(this).next().show();
  };
};

//when even happens on password input
$("#password").focus(passwordEvent).keyup(passwordEvent); 

//WHen event happens on confirmation input
  //Find out if password and configuration match
    //Hide hint if match
    //else show hint

1 Answer

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

I'd need to see your HTML as well, but without seeing it, I would say make sure that your hints are within span elements that are inside of your form element.

Also, the semicolons at the end of your passwordEvent() function are unnecessary

function passwordEvent() {
  //Find out if the password is valid
  if($(this).val().length > 8) {
    //Hide hint if valid
    $(this).next().hide();
  } else {
    //else show hint
    $(this).next().show();
  }//; this one can be removed
}//; this one can go as well

No need for semicolons in if statements. Also no need for them with functions unless you store the function in a variable like this

var passwordEvent = function(){
  //function stuff here
};