Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Last active August 29, 2015 14:10
Show Gist options
  • Save RobAWilkinson/14082d6e1f15778a40a3 to your computer and use it in GitHub Desktop.
Save RobAWilkinson/14082d6e1f15778a40a3 to your computer and use it in GitHub Desktop.
Age Check JS
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