Homework 3

  1. Create a page where a user enters a password twice. Check to see if the passwords match. Print an error message via an alert if they don’t match, or show a confirmation message if they do match.

Here’s an html document to use for the rest of the exercises.
  1. Write code that, when the button is clicked, will check to see if the year the user entered is a number. If it is not a number, show an alert that asks them to enter a valid value.
  2. Write a function that will check if they were born on a leap day (02/29 of any year). If they were, show an alert that says "Leap day - nice!".
  3. For this exercise, you'll need to add this line to your code. I'd stick it right at the beginning of your function.
    var date = new Date();

    With that, you can do the following:

    • date.getFullYear() will get you the 4-digit year
    • date. getMonth() will get you the month, numbered 0 (for January) to 11 (december)
    • date. getDate() will get the current day of the month (1-31)
    Write a function that gets called when the button is clicked. The function should check to see if the person who typed in their birthday is 21 or over. If they are over 21, show an alrt “old enough”. If they are too young, alert “too young”.