![]() |
Start | Time | IF | Date Object | Arrays | Avoid the work | Hide email | Random | Intigrate HTML | Test |
![]() |
The Date Object JavaScript has several handy functions built right into it. Here we deal with time. To get the time JavaScript will read it from your own computer and then give it to you when you call for new Date ( ) This is where we must define a variable. A variable is simply a name that JavaScript can use to store its data. In this case we will use the name 'now' and have JavaScript fill it with all the info from your computer's clock.
For now let us just find the year We use another variable and fill it with the year like so
To print this variable on the page we use document.write like this
Now we have a variable 'yr' that we can play with but first let us put a variable with some regular text into document.write( ) All we do is put a + sign between variables and regular text. 'The year is now '+yr To review this is how you would print the current year.
Ok, we can print out meaningful text with JavaScript so now let us play with a variable. Let us figure out our age and print it for all to see. Make a new variable 'age' and simply subtract your birth year from the current year 'yr'. (I'll use my own )
Next : Those little adjustments Home |