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 2

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

Hello,

I can't understand this line very well.

I understand why the () is not necessary at the end of "passwordEvent" and "confirmPasswordEvent" but I don't know how this line works.

Could you help me please?

Thank you.

I'm not sure if this is correct, but basically my understanding of what happens is this:

1) when the password field is selected, it calls the passwordEvent function to check if the password is valid (i.e. has more than 8 characters) and to hide/show the hint. 2) after each keypress, it calls the passwordEvent function to check if the password is valid and to hide/show the hint.

That's what it was doing before, but the problem was that if you wrote the password, wrote the confirmation, and then changed the password in the first field, the tips would no longer be correct.

So we add the confirmPasswordEvent function to the inputs on the password field.

3) when the password field is selected, it calls the confirmPasswordEvent function to check if the password and the password confirmation are the same 4) after each keypress, it calls the confirmPasswordEvent function to check if the password and the password confirmation are the same.

This makes it so if things match, and then a change is made so that they don't, the system provides the appropriate tip.