- #1
renob
- 89
- 0
Homework Statement
I'm supposed to write a program that upon clicking a command button generates a random number, and displays 1 of 7 images that is associated with the random number generated.
Ive been at this for a few hours and can't get the image to change.
EDIT:
Upon further testing it seems to work on firefox, but not on internet explorer, which is the browser that it will be tested on.
Anyone know what's going on here?
The Attempt at a Solution
Code:
<html>
<head><title>Assignment #5</title></head>
<script language="Javascript">
function random()
{
number=Math.floor(Math.random()*7);
number=number + 1;
caption= "your number is" + " " + number;
if(number==1)
{
OutputArea.innerText=caption;
document.images.src="al.jpg";
}
else if(number==2)
{
OutputArea.innerText=caption;
document.images.src="city.jpg";
}
else if(number==3)
{
OutputArea.innerText=caption;
document.images.src="dance.jpg";
}
else if(number==4)
{
OutputArea.innerText=caption;
document.images.src="good.jpg";
}
else if(number==5)
{
OutputArea.innerText=caption;
document.images.src="kiss.jpg";
}
else if(number==6)
{
OutputArea.innerText=caption;
document.images.src="sleep.jpg";
}
else if(number==7)
{
OutputArea.innerText=caption;
document.images.src="vince.jpg";
}
}
</script>
<body bgcolor=blue text=white onload="random()">
<center>
//initiates function
<input type="button" value="images" title="click to dislpay image" onclick="random()">
// where the messege is displayed
<B ID="OutputArea">
// where the image is displayed
<img src="al.jpg" name="images">
</body>
</html>
Last edited: