When the player presses on New Game, it should randomly assign a blue or yellow button to each image.
here is the work I did so far:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<title>Project_5</title>
</head>
<body bgcolor="#FFFFFF">
<script language="JavaScript">
<!--
function newGame()
{
var x
for(i=0;i<10;i++)
{
x = Math.random();
if(x==0)
{
window.document.image[i].src = "BlueButton.gif"
}
elseif(x==1)
{
window.document.image[i].src = "YellowButton.gif"
}
}
}
}
function doButton(0)
{
if(document.img.color[0].src=="BlueButton.gif")
{
document.img.color[2].src = "YellowButton.gif";
document.img.color[4].src = "YellowButton.gif";
}
elseif(document.img.color[0].src=="YellowButton.gif")
{
document.img.color[2].src = "BlueButton.gif";
document.img.color[4].src = "BlueButton.gif";
}
}
function doButton(1)
{
if(document.img.color[1].src=="BlueButton.gif")
{
document.img.color[0].src = "YellowButton.gif";
document.img.color[2].src = "YellowButton.gif";
document.img.color[4].src = "YellowButton.gif";
}
elseif(document.img.color[1].src=="YellowButton.gif")
{
document.img.color[0].src = "BlueButton.gif";
document.img.color[2].src = "BlueButton.gif";
document.img.color[4].src = "BlueButton.gif";
}
}
function doButton(2)
{
if(document.img.color[2].src=="BlueButton.gif")
{
document.img.color[1].src = "YellowButton.gif";
document.img.color[5].src = "YellowButton.gif";
}
elseif(document.img.color[2].src=="YellowButton.gif")
{
document.img.color[1].src = "BlueButton.gif";
document.img.color[5].src = "BlueButton.gif";
}
}
function doButton(3)
{
if(document.img.color[3].src=="BlueButton.gif")
{
document.img.color[0].src = "YellowButton.gif";
document.img.color[4].src = "YellowButton.gif";
document.img.color[6].src = "YellowButton.gif";
}
elseif(document.img.color[3].src=="YellowButton.gif")
{
document.img.color[0].src = "BlueButton.gif";
document.img.color[4].src = "BlueButton.gif";
document.img.color[6].src = "BlueButton.gif";
}
}
function doButton(4)
{
if(document.img.color[4].src=="BlueButton.gif")
{
document.img.color[1].src = "YellowButton.gif";
document.img.color[3].src = "YellowButton.gif";
document.img.color[5].src = "YellowButton.gif";
document.img.color[7].src = "YellowButton.gif";
}
elseif(document.img.color[4].src=="YellowButton.gif")
{
document.img.color[1].src = "BlueButton.gif";
document.img.color[3].src = "BlueButton.gif";
document.img.color[5].src = "BlueButton.gif";
document.img.color[7].src = "BlueButton.gif";
}
}
function doButton(5)
{
if(document.img.color[5].src=="BlueButton.gif")
{
document.img.color[2].src = "YellowButton.gif";
document.img.color[4].src = "YellowButton.gif";
document.img.color[8].src = "YellowButton.gif";
}
elseif(document.img.color[5].src=="YellowButton.gif")
{
document.img.color[2].src = "BlueButton.gif";
document.img.color[4].src = "BlueButton.gif";
document.img.color[8].src = "BlueButton.gif";
}
}
function doButton(6)
{
if(document.img.color[6].src=="BlueButton.gif")
{
document.img.color[3].src = "YellowButton.gif";
document.img.color[7].src = "YellowButton.gif";
}
elseif(document.img.color[6].src=="YellowButton.gif")
{
document.img.color[3].src = "BlueButton.gif";
document.img.color[7].src = "BlueButton.gif";
}
}
function doButton(7)
{
if(document.img.color[7].src=="BlueButton.gif")
{
document.img.color[4].src = "YellowButton.gif";
document.img.color[6].src = "YellowButton.gif";
document.img.color[8].src = "YellowButton.gif";
}
elseif(document.img.color[7].src=="YellowButton.gif")
{
document.img.color[4].src = "BlueButton.gif";
document.img.color[6].src = "BlueButton.gif";
document.img.color[8].src = "BlueButton.gif";
}
}
function doButton(8)
{
if(document.img.color[8].src=="BlueButton.gif")
{
document.img.color[5].src = "YellowButton.gif";
document.img.color[7].src = "YellowButton.gif";
}
elseif(document.img.color[8].src=="YellowButton.gif")
{
document.img.color[5].src = "BlueButton.gif";
document.img.color[7].src = "BlueButton.gif";
}
}
//-->
</script><br>
<FORM ID=img NAME=img>
<p align="center"><font size="5">Click a button to change it and
its neighbors. <br>
To win, turn the center button yellow and the rest to blue.</font>
</p>
<p align="center"><img src="BlueButton.gif" width="30"
height="30" onclick="doButton(0)"> <img src="BlueButton.gif"
width="30" height="30" onclick="doButton(1)"> <img
src="BlueButton.gif" width="30" height="30" onclick="doButton(2)">
<br>
<img src="BlueButton.gif" width="30" height="30"
onclick="doButton(3)"> <img src="BlueButton.gif" width="30"
height="30" onclick="doButton(4)"> <img src="BlueButton.gif"
width="30" height="30" onclick="doButton(5)"> <br>
<img src="BlueButton.gif" width="30" height="30"
onclick="doButton(6)"> <img src="BlueButton.gif" width="30"
height="30" onclick="doButton(7)"> <img src="BlueButton.gif"
width="30" height="30" onclick="doButton(8)"> </p>
<p align="center"><input type="submit" name="B1" value="New Game"
onClick="newGame()"></p>
</FORM>
</body>
</html>
Can someone help debug it for me? i think i have alot of errors on this one.
