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

Confused about focus, keyup, and when to use different JavaScript functions

For the last part of the password form exercise, I'm getting tangled up in when and how to call certain functions. I rewatched the video but the intuition is still not coming nor is anything clicking. Why would we have, for example, the following:

    ....

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

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

    ....

Can anyone give me examples to better explain this? Thanks!

2 Answers

Daniel Wilson
Daniel Wilson
5,929 Points

They just want you to add the .focus and .keyup methods and pass in confirmPasswordEvent, like this...

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

For this code ...

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

It's saying:

If the user focuses on the password input then run the passwordEvent function or If the user is focused on the password input and types a key, run all of these functions: passwordEvent and confirmPasswordEvent and enableSubmitEvent

Does that help?