Confirm a Password

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

A form has two password inputs, labelled "Password" and "Confirm password", and a "Set password" button. While Confirm password is empty, show no message. Once something is typed there, show "Passwords do not match" if the two differ, or "Passwords match" if they are the same, and keep it up to date when either one changes. The button is disabled unless both are filled in and match. Clicking it replaces the form with "Password set".

Your code must pass

  • No message shows before you confirm
  • Different passwords show a warning and keep the button disabled
  • Matching passwords enable Set password
  • Changing the first password checks the match again
  • Set password confirms it