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

Jonas Troyer
Jonas Troyer
10,912 Points

Why aren't my functions being defined in the code.

When I run my functions trying to debug this code in the console it says that all my functions are undefined. I can't find the error anywhere and have no idea what is going on.

I have no idea how to submit code on this thing, you think there would be a workspace submit place on the side or something.

//Problem:Hints are shown even when form is valid
//Solution: Hide and show them at appropriate 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 canSubmit() {
  return isPasswordValid() && arePasswordsMatching();

function passwordEvent() {
   if(isPasswordValid()) {
    //Hide hints if valid
    $password.next().hide();
  } else {
    $password.next().show();
  //Else show hint
  }
}

function confirmPasswordEvent() {
  if(arePasswordsMatching()) {
    $confirmPassword.next().hide();
  } else {
    $confirmPassword.next().show();
  }
}

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);
  //Find out if password is valid
//When event happen on confirmation input
  //Find out if password and confirmation match
  //Hind hints if matched
  //else show the hint
  enableSubmitEvent();
Hugo Paz
Hugo Paz
15,622 Points

Hi Jonas,

We cant help you if you dont put your code here. Please post the code you have.

1 Answer

Damien Watson
Damien Watson
27,419 Points

Hey Jonas,

Looks like there is a missing bracket in your 'canSubmit' function:

function canSubmit() {
  return isPasswordValid() && arePasswordsMatching();
}

function passwordEvent() {
...
}