January 5, 2011
-
age.js
/*This script checks the date you were born against the current date.*/
/*It then outputs your age via document.write. */
/*Feel free to use this script, but please give credit to myself */
/* ~~~Vangrat~~~ *//*****INPUT THE BIRTHDATE DETAILS BELOW****/
/*——————————————————————————————*/
var bday= 2; //day of month born
var bmo= 1; //month of year born
var byr= 1984; //year born
/*——————————————————————————————*/
/****END INPUT****//****START SCRIPT****/
/*——————————————————————————————-*/
var age; //current age
var now = new Date(); //call for date from your computer
tday=now.getDate(); //today’s day of the month
tmo=(now.getMonth())+1; //today’s month of the year
tyr=(now.getFullYear()); //today’s yearif(tyr>=byr){ //If this year is greater then or
//equal to the year you were born.if(tmo>=bmo){ //If this month is greater then or
//equal to the month you were born.if(tday>=bday){ //If this day is greater then or
//equal to the day you were born.age=tyr-byr; //Your age is equal to this year
//subtracted from your birth year.}else //otherwise
if(tday<bday){ //If this is the right month and year
//but today is less then your birthday
age=tyr-byr-1; //your age is equal to this year minus
//your birthyear, minus one.
}
}else //On the other hand, if this is the
if(tmo<bmo){ //right year but wrong month, your
age=tyr-byr-1; //age is equal to this year minus your
//birth year, minus one.
}
}else{ //If all the above is not true, then
age=”Not born yet.”; //you have not been born yet.
}if(age<=0){ //If the person has just been born
if((age+1)==1){ //(this is a logic check to ensure the
//integer returned is a positive number)age=”New born.”; //assign “New Born.” to age.
}else{ //otherwise,
age=”Not born yet.”; //a person cannot be negative years old!
}
}document.write(age); //output age
/*———————————————————————————————–*/
/****END SCRIPT****/
Comments (2)
I have no idea what I’d use that for, but…
Does this mean you’re done philosophizing???
@warweasel - I don’t think I will ever be done philosophizing :3
However, this is a javascript code that will automagically update your age on any website you attach it to. I have used this script to update my age in my e-Portfolio. This way I don’t have to change it each year I get older.