HTML and CSS Reference
The function called weekDay() is defined.
The variable now is assigned a number representing the day of the week, where 0
A new Array object called names is created. It will contain seven elements. Each
element will be assigned the name of the weekday (e.g., “Sunday”) .
The value in now , a number between 0 and 6, will be used as an index in the names
array. If now is 6, then the value of names , “Saturday” , will be returned.
A prototype method called DayOfWeek is assigned the name of the function week-
Day . Now the Date object has a new method that will be inherited by all objects
created from the Date() constructor. The capabilities of the Date object have been
extended to provide a method that will return the name of the weekday. (See
Chapter 8 for more on prototypes.)
A new Date object is created with the Date() constructor function.
The new prototype method is called, and returns the string value of today's date,
“Saturday” (see Figure 9.23).
Figure 9.23 The day is converted to a string using a prototype.
The Math object allows you to work with more advanced arithmetic calculations, such
as square root, trigonometric functions, logarithms, and random numbers, than are pro-
vided by the basic numeric operators. If you are doing simple calculations, you really
won't need it.
Unlike other objects, you don't have to create an instance of the Math object with the
new keyword. It is a built-in object and has a number of properties (see Table 9.5) and
methods (see Table 9.6). The Math object always starts with an uppercase M.
Table 9.5 Math Object Properties
Euler's constant, the base of
Natural log of 2
Natural log of 10