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

A better code?

HI, i think a better code might be:

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

because when the $password is focused, its not necessary to run confirmPasswordEvent to check if the password matches because the event of simply focusing on the $password input element will never change the value inside. Instead, only three ways can the value inside be changed:

  1. someone type something (keyup)
  2. copy and paste something using keyboard shortcut (keyup)
  3. copy and paste using mouse only (mouseleave)

so we should never run confirmPasswordEvent on $password.focus and always run it on keyup() and mouseleave()

Do you guys think this is right?