Java Reference
In-Depth Information
document.imgAdvert.src = “AdvertImage” + selectedImage + “.jpg”;
}
</script>
</head>
<body onload=”window_onload()”>
<img src=”AdvertImage1.jpg” name=”imgAdvert” />
</body>
</html>
Save this as ch10_q1.htm .
This solution is based on the example in the chapter, Adverts.htm , where you displayed three images
at set intervals one after the other. The fi rst difference is that you select a random image each time,
rather than the images in sequence. Second, you make sure you don't select the same image twice in
one sequence by having an array, imagesSelected , with each element of that array being true or
false depending on whether the image has been selected before. Once you've shown each image, you
reset the array and start the sequence of selecting images randomly again.
The fi nal difference between this solution and the example in the chapter is that you set the timer going
continuously with setInterval() . So, until the user moves to another page, your random display of
images will continue.
Exercise 2 Question
Create a form that gets the user's date of birth. Then, using that information, tell them on what day of
the week they were born.
Exercise 2 Solution
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<script type=”text/javascript”>
var days = new Array();
days[0] = “Sunday”;
days[1] = “Monday”;
days[2] = “Tuesday”;
days[3] = “Wednesday”;
days[4] = “Thursday”;
days[5] = “Friday”;
days[6] = “Saturday”;
function dayOfWeek()
{
var form = document.form1;
Search WWH ::




Custom Search