. 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 -------------- -->
JavaBabyAger
by Alex Kasman
The JavaBabyAger is a short Java script which computes and prints the current age of a baby (or anything else, of course). NOTE: It only works if people have Java capable browsers and have the correct date set on their computer! Originally written for my daughter's web page, the ager is available here for your use in case you want to use it on your own page.
Here is an example of what it looks like...computing my own age:
If you want to use this script on one of your own pages, that is fine with me. It is free (although I wouldn't mind some money if you have any to spare!) but
- I do not make any guarantees that it will always work correctly
- nor do I promise to help you install it if you are having problems
- I request that you keep my name and the link to my page associated with the script.
If you accept all of that, then download and read this file which contains nothing but the script and an explanation of how to insert it into your own document. (Note: you must read the SOURCE code for this file...if you just look at it on your browser you won't see much.)
Thanks! Alex
Alex Kasman's Software Distribution Page
Alex Kasman's Home Page