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 Perfect

The "hints" are no longer showing up after enableSubmitEvent()

For some reason after adding the canSubmit() and enableSubmitEvent() functions, the password "hints" are no longer showing up. They were working perfectly in the previous video...code below. Thanks!!

// hints are shown even when form is valid
// hide and show them at appropriate times

var $password = $("#password");
var $confirmPassword = $("#confirm_password");
var $submit = $("#submit");


// hide hints

$("form span").hide();

function isPasswordvalid() {
  return $password.val().length > 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, else show hint
    $password.next().hide(); 
  } else {
    $password.next().show();
  }
}

function confirmPasswordEvent() {
// find out if password and confirmation match
  if (arePasswordsMatching) {
    $confirmPassword.next().hide();
  } else {
    $confirmPassword.next().show();
// hide hint if match, else show hint  
  }
}

function enableSubmitEvent() {
  $submit.prop("disabled", !canSubmit());
}

// when event happens on password input:

$password.focus(passwordEvent).keyup(passwordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

// when event happens on confirmation

$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

// disable button immediately on load  
enableSubmitEvent();

1 Answer

It's an old topic but I will try to answer :)

You forgot to add parenthesis when you call isPasswordvalid() and arePasswordmatching() functions:

it should be:

function passwordEvent() {
// find out if password is valid
  if (isPasswordvalid()) { 
...

function confirmPasswordEvent() {
// find out if password and confirmation match
  if (arePasswordsMatching()) {
  ... 

Best regards, Damian