The following are examples of Math, Number and Date Objects.
Understanding Math
The Math object can be useful when you need to preform various calculations in your scripts. The Math object is a predefined JavaScript object. Like the other predefined objects we ahve worked with, the Math object gives you properties and methods to use. The Math object is used for mathematical purposes to give you the values of certain mathematical constants or to perform certain operations when you use a method function.
For this example, we will be discussing and showing a random() Method. The random() method is very useful for creating scripts that require random integers. It returns a random number between 0 and 1. This means that you get a number with a decimal that can be quite long and not useful on its own. For instance, it might return something like o.36511165498095293.
To get a random intger that you can use, you need to do some things to get the type of value you want to use. We are going to have some fun with quotes!
Random Quotes for Fun
In the area below are going to be random quotes. I have created 15 quotes in the head of this document page and will use the window.alert (pop-up) to call them here.
Random Thoughts For Today: (to see a new thought, refresh the page)
All quotes obtained from The Quotations Page.
Understanding Date Object
The Date Object is another predefined JavaScript object. It enagles you to set certain time vaules and to get certain time values that you can use in your scripts. To use this object, you need to create an instance of the object which you can refer.
Once you have an instance of the object, you can use the properties and methods of the Date object to perform various task (such as cate JavaScript clocks).
For this example we will show you todays date.
The Current Date and Time is:
Now if you look down on the status bar (in IE), you will see not only today's date but the time!