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

Remi Vledder
Remi Vledder
14,144 Points

wrap it up in an anonymous function (video transcript 8:49)

By the end of the movie clip you mention at 8:49 "You may want to wrap this up in an anonymous function, and you call the password and the confirmed password together on two separate lines."

Can you provide a example?

Tagging Andrew Chalkley

1 Answer

Remi,

I'm guessing he meant something like this:

// When event happens on password input
$password.focus(function() {
  passwordEvent();
  confirmPasswordEvent();
}).keyup(function() {
  passwordEvent();
  confirmPasswordEvent();
});

Although I'd really like to see someone with more experience, or better yet, the instructor himself, provide an example of what he meant. If it's like what I wrote above, to me that looks more confusing than the original line:

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

Which can be cleaned up by doing:

$password.on("focus keyup", function() {
  passwordEvent();
  confirmPasswordEvent();
});

Hi Fidel,

That last one seems like a good idea. I hadn't thought of that.