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

CSS jQuery Basics (2014) Creating a Password Confirmation Form Perfect

Syntax errors?

My browser does not seem to want to accept the 'else' portion of the loop in the function passwordEvent. Any ideas around this?

You have to post your code. Refer to the Markdown Cheatsheet below on the formatting. It is almost certainly a syntax problem.

2 Answers

```// problem: hints are not disappearing and the confirm password needs to err if wrong //solution: hide and show hints 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(){ //find out if password is valid if(isPasswordValid()); { // hide hint if valid $password.next().hide(); }else { // else show hint $password.next().show(); } }

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

function enableSubmitEvent() { $("#submit").prop("disabled", !canSubmit()); // ! is used because canSubmit is a boolean value }

//when event happens on password input $password.focus(passwordEvent).keyup(passwordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

//when event happens on confirmation input $confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

enableSubmitEvent();

markdown is three back ticks followed by the language. Begin your quote on the next line. End the quote with three back ticks on the line after your quote.

// problem: hints are not disappearing and the confirm password needs to err if wrong //solution: hide and show hints 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(){ 
//find out if password is valid 
if(isPasswordValid()); 
{ // hide hint 
if valid $password.next().hide(); 
}else { 
// else show hint 
$password.next().show(); 
} 
}

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

function enableSubmitEvent() { 
$("#submit").prop("disabled", !canSubmit()); 
// ! is used because canSubmit is a boolean value 
}

//when event happens on password input $password.focus(passwordEvent).keyup(passwordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

//when event happens on confirmation input $confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent).keyup(enableSubmitEvent);

enableSubmitEvent();

I spent time formatting with more standard page breaks, but did not indent because of browser limitations. I put a line break after each semicolon. It appears you have an extra semicolon on this line:

if(isPasswordValid()); 

That function has no curly brace because of the semicolon.