. Then insert that into the
of your own
// document. (This means it must appear between the and
// commands of your html document.) In fact, you will want to edit this
// part of the script because that is where the name and birthdate of your
// baby (or dog or whatever) is entered. See below...
// 2) Then you must also add a small bit to the command of your
// html document. You must add the string `onLoad="findage()"' so that
// the body starts with the command
//
// (other options can also appear inside the BODY command, like setting
// text color and stuff, but you must include the onLoad somewhere.)
// 3) Finally, you must also include the html code below into your document.
// This code appears below and starts with the command and ends with
// . You can modify it a little if you want to change the appearance,
// but please leave the link to my web page. Thanks. -Alex
function findage(){
now = new Date();
// YOU MUST SET THE INFORMATION BELOW!
bname = "Alex" // <---This is the baby's name
bmon = 1; // <--- this is the month of the baby's birth (1=jan, 2=feb....)
bdat = 20; // <--- this is the day of the month on which the baby was born
byr = 67; // <---this is the year of the baby's birth (drop the leading "19")
// Now I compute the present age
dat = now.getDate();
yr = now.getYear();
// This is a hack to get the script to work until the year 2020
if (yr<20)
yr=yr+100;
mon = now.getMonth();
pls = 0;
if (dat>bdat-1)
pls = 1;
xtra = "";
if (dat==bdat)
xtra = "EXACTLY ";
yrs=yr-byr;
ptyrs="";
if (yrs>1)
ptyrs=yrs+" years and ";
if (yrs>1)
yrs=0;
mons=12*yrs+(mon-bmon)+pls
document.ager.months.value = bname+" is now "+xtra+ptyrs+mons+" months old!"
}
// -- End of JavaScript code -------------- -->