search711
05-26-2009, 04:28 PM
I'm wanting to know how I would return a value with randomInteger().
This is for visual confirmation with images 0-9 all images. Are 0.jpg through
9.jpg.
function randomInteger(size) {
return Math.floor((size+1)*Math.random());
}
I'm placing this code in External file sheet.
The question to my problem is:
Add a second script element for code to be placed in the document.
within the second script element, create a function named showImg(). The purpose of this function is to write an inline image into the current document document. The function has no parameters. Add the following statements to the function:
a. Add the following multiline comment to the start of the showImg()function: The showImg() function displays a random to thwart hackers attempting to enter the library records database by requiring visual confirmation.
b. Declare a varible and named imgNumber equal to the value returned by the randomInteger() function. Use 9 as the value of the size parameter int he randomInteger() function.
c. Append the statement that creates the imgNumber variable with the following single-line comment.
Return a random number from 0-9
d. insert a command that writes the following the text to the document:
<img src='imgNumber.jpg' alt=' ' />..I guesing it will a image num. 0.jpg for instance.
5.Scroll down to the bottom of the file and locate the last table cell in the document. Within this empty table cell, insert a script element.
6. Within the script element, call the showImg()function five times.
<title>Monroe Public Library</title>
<link href="mplstyles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="random.js"></script>
</head>
<body>
<p id="head">
<img src="mpl.jpg" alt="Monroe Public Library" />
</p>
<div id="links">
<span>Quick Links</span>
<a href="#">Home Page</a>
<a href="#">Online Catalog</a>
<a href="#">Friends of MPL</a>
<a href="#">New Books and Other Good Reading</a>
<a href="#">Illinois Virtual Library</a>
<a href="#">Internet Public Library</a>
<a href="#">Services and Collection</a>
<a href="#">Adult Programs</a>
<a href="#">Teen Central</a>
<a href="#">Children's Room</a>
<a href="#">Computers at MPL</a>
<a href="#">Computer Rules and Procedures</a>
<a href="#">Staff Directory</a>
<a href="#">Library Records</a>
</div>
<div id="main">
<h2>Library Records</h2>
showImg()
<p>To view the library records, enter your username and password.</p>
<table border="1" cellpadding="5" cellspacing="0">
<tr>
<th>Username</th>
<td><input size="20" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" size="20" /></td>
</tr>
<tr>
<td>As a final security check, enter the 5 numbers
you see displayed below.</td>
<td><input size="6" /></td>
</tr>
<tr>
<td colspan="2" class="center">
<input type="button" value="View Library Records" />
</td>
</tr>
<tr>
<td colspan="2" class="center">
</td>
</tr>
</table>
</div>
<address>
<b>Monroe Public Library</b>
580 Main Street, Monroe IL 45812 54890
<b>Phone</b>(612) 555-0211
<b>Fax</b>(612) 555-0241
</address>
</body>
</html>
This is for visual confirmation with images 0-9 all images. Are 0.jpg through
9.jpg.
function randomInteger(size) {
return Math.floor((size+1)*Math.random());
}
I'm placing this code in External file sheet.
The question to my problem is:
Add a second script element for code to be placed in the document.
within the second script element, create a function named showImg(). The purpose of this function is to write an inline image into the current document document. The function has no parameters. Add the following statements to the function:
a. Add the following multiline comment to the start of the showImg()function: The showImg() function displays a random to thwart hackers attempting to enter the library records database by requiring visual confirmation.
b. Declare a varible and named imgNumber equal to the value returned by the randomInteger() function. Use 9 as the value of the size parameter int he randomInteger() function.
c. Append the statement that creates the imgNumber variable with the following single-line comment.
Return a random number from 0-9
d. insert a command that writes the following the text to the document:
<img src='imgNumber.jpg' alt=' ' />..I guesing it will a image num. 0.jpg for instance.
5.Scroll down to the bottom of the file and locate the last table cell in the document. Within this empty table cell, insert a script element.
6. Within the script element, call the showImg()function five times.
<title>Monroe Public Library</title>
<link href="mplstyles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="random.js"></script>
</head>
<body>
<p id="head">
<img src="mpl.jpg" alt="Monroe Public Library" />
</p>
<div id="links">
<span>Quick Links</span>
<a href="#">Home Page</a>
<a href="#">Online Catalog</a>
<a href="#">Friends of MPL</a>
<a href="#">New Books and Other Good Reading</a>
<a href="#">Illinois Virtual Library</a>
<a href="#">Internet Public Library</a>
<a href="#">Services and Collection</a>
<a href="#">Adult Programs</a>
<a href="#">Teen Central</a>
<a href="#">Children's Room</a>
<a href="#">Computers at MPL</a>
<a href="#">Computer Rules and Procedures</a>
<a href="#">Staff Directory</a>
<a href="#">Library Records</a>
</div>
<div id="main">
<h2>Library Records</h2>
showImg()
<p>To view the library records, enter your username and password.</p>
<table border="1" cellpadding="5" cellspacing="0">
<tr>
<th>Username</th>
<td><input size="20" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" size="20" /></td>
</tr>
<tr>
<td>As a final security check, enter the 5 numbers
you see displayed below.</td>
<td><input size="6" /></td>
</tr>
<tr>
<td colspan="2" class="center">
<input type="button" value="View Library Records" />
</td>
</tr>
<tr>
<td colspan="2" class="center">
</td>
</tr>
</table>
</div>
<address>
<b>Monroe Public Library</b>
580 Main Street, Monroe IL 45812 54890
<b>Phone</b>(612) 555-0211
<b>Fax</b>(612) 555-0241
</address>
</body>
</html>