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

Peter Gess
Peter Gess
16,553 Points

Unexpected Token else

The boxes are not hiding and I am getting the following error in the console: app.js:14 Uncaught SyntaxError: Unexpected token else

CODE:

//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 password is valid if($(this).val().length > 8); { //Hide hint if valid $(this).next().hide(); } else { //Else show hint $(this).next().show(); }

}

//When event happens on password input $("#password").focus(passwordEvent).keyup(passwordEvent);

//When event happens on confirmation input //Find out if password and confirmation match //Hide hint if match //Else show hint

1 Answer

Steven Parker
Steven Parker
229,708 Points

You seem to have a stray semicolon.

On the line after the comment "//Find out if password is valid ", there is a semicolon between the final parenthesis of the conditional expression and the open brace of the code block.

It was a bit tough to tell the difference between the comments and the code! In future postings, please use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:

Peter Gess
Peter Gess
16,553 Points

Simple mistake! Thank you.