HTML and CSS Reference
In-Depth Information
the random number by taking the size of the array (randomImage.length) and subtracting
1 from that size. This subtraction is necessary because an array's first element is identified
as element zero. Line 26 generates the random number using the Math.ceil() method and
Math.random() methods. The Math.random() method generates a number between 0 and 1.
The result is multiplied by the array size, which in this case is seven, minus one to give us six
(the rndnumsize).
The multiplication by the array size provides a number between 1 and 7, and the
Math.ceil() method will round the value to the next integer, which is assigned to the
variable randomnumber. The randomnumber value is used in line 27 to assign an array
element to the image placeholder. Line 28 closes the function.
To Enter a Random Number Generator User-Defined Function
The following step enters the user-defined function, rndimage(), to randomly assign an image to the image
placeholder.
1
null entry because
zero element is
never generated
Click line 22 and press
the e n t e r key once.
On line 23, enter
the JavaScript code
shown in Table 11-8
to create the user-
defined function to
randomly assign an
image to the image
placeholder, as shown
in Figure 11-10.
line 23 fills array
of images for
random display
Math.random()
function generates
random number
random number used to
pick image from array and
display on Web page
Press the
e n t e r
key once.
Figure 11-10
To Enter Code to Show Copyright Information and Date Last Modified
As shown in Figure 11-1a on page HTML 509, the Hickory Oaks Forest Preserve Home page displays
copyright information, the date the file was last modified, and the URL at the bottom of the Web page. To show just
the date, without the time, the JavaScript code uses the substring() method, which was introduced in Chapter 10.
First, however, a <div> or <footer> container tag with an id attribute must be inserted in the HTML code where the
message is to display. Table 11-9 shows the HTML code for the <footer> tag with the id attribute and class attribute
for formatting the copyright display. By adding a class attribute, a style sheet entry can format the text for this
container, eliminating the need for an inline style.
Table 11-9 Code for <footer> Tag with the id and class Attributes
Line
Code
119
<footer id=”displayCopyRight” class=”footer_format”>
120
</footer>
Table 11-10 on the next page shows the JavaScript code for the <script> section to show the copyright
information and date the Web page was last modified.
 
Search WWH ::




Custom Search