Hi,
i wonder if someone could help me. I am writing a very simple rock paper scissors program using javascript. The basic requirements are that you ckick a play button, the program randomly generates two numbers, two pictures (one for each player) are displayed and the winners score is incremented. Now I’ve got all this working……..on Internet Explorer 6…….and nothing else. Can anyone tell me where I’ve gone wrong in the code below. (required pictures are attached as a zip file)
Thanks,
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
<html xmlns=”
<head>
<title>Rock Paper Scissors</title>
</head>
<body>
<FORM>
<SCRIPT LANGUAGE=”JavaScript”>
var Players_Choice;
var Computers_Choice;
var imageArray = new Array(3);
for (var i=0 ; i<3 ; i++)
imageArray[i] = new Image();
imageArray[0].src=”stone.gif”;
imageArray[1].src=”scissors.gif”;
imageArray[2].src=”paper.gif”;
function playGame() {
Players_Choice=(Math.round(Math.random()*2)+1);
document.user_image.src = imageArray[Players_Choice-1].src;
intervalID1 = setInterval(‘SwitchImage();’,100);
setTimeout(‘results(intervalID1);’,700);
}
function SwitchImage(){
Computers_Choice=(Math.round(Math.random()*2)+1);
document.comp_image.src = imageArray[Computers_Choice-1].src;
}
function results(intervalID1) {
clearInterval(intervalID1);
//player wins
if ( (Players_Choice == 1 && Computers_Choice == 2) ||
(Players_Choice == 2 && Computers_Choice == 3) ||
(Players_Choice == 3 && Computers_Choice == 1)){
playwin.value++;
document.winnerimage.src =”2wins.gif”;
}
// Its a draw
else if ( Players_Choice == Computers_Choice ){
document.winnerimage.src =”draw.gif”;
}
// computer wins
else {
compwin.value++;
document.winnerimage.src =”1wins.gif”;
}
if (playwin.value == 5){
alert(“The Player has won”);
playwin.value= 0;
compwin.value=0;
}
else if (compwin.value == 5){
alert(“The Computer has won”);
compwin.value=0;
playwin.value= 0;}
}
if (compwin.value == 5 || playerwin.value == 5){
}
</script>
</form>
<table align = “center” width=”500″ border=”0″>
<tr>
<td align=center><h3>Computer</h3></td>
<td> </td>
<td align=center><h3>Player</h3></td>
</tr>
<tr>
<td align=center rowspan=”2″><img border=0 NAME=”comp_image” src=”stone.gif” width=125 height=150 /></td>
<td align=center> <a href=”javascript:;” onClick=playGame(2);><input type = button value = “Play” /></a>
<td align=center rowspan=”2″><img border=0 NAME=”user_image” src=”paper.gif” width=125 height=150 /></td>
</tr>
<tr>
<td align=center><img border=”0″ NAME =”winnerimage” src=”draw.gif” width=”70″ height=”50″></td>
</tr>
<tr>
<td align=center><input type=text name=compwin readonly value=”0″ size=”2″></td>
<td></td>
<td align=center><input type=text name=playwin readonly value=”0″ size=”2″></td>
</tr>
</table>
</body>
</html>
[upl-file uuid=2bcf8077-a21e-45c6-abae-460f51a02378 size=16kB]my effort.zip[/upl-file]