Last active
August 29, 2015 14:10
-
-
Save RobAWilkinson/14082d6e1f15778a40a3 to your computer and use it in GitHub Desktop.
Age Check JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var today = new Date(); | |
var todayYear = today.getFullYear(), | |
todayMonth = (today.getMonth() + 1), | |
todayDate = today.getDate(); | |
var birthdayYear = prompt("What year were you born?"), | |
birthdayMonth = prompt("What month"), | |
birthdayDate = prompt("What Day were you born?"); | |
if ((todayYear - birthdayYear) > 21) { | |
console.log(21); | |
} | |
else if ((todayYear - birthdayYear) == 21){ | |
if (todayMonth > birthdayMonth){ | |
if (todayDate > birthdayDate) { | |
console.log(21); | |
} | |
console.log(21); | |
} | |
else if ((todayMonth == birthdayMonth) && (todayDate == birthdayDate)){ | |
console.log("HAPPY 21st BDAY"); | |
} | |
} | |
else { | |
console.log("too young"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment