<table>
<tr>
<td colspan="3">Rock Paper Scissors</td>
</tr>
<tr>
<td onclick="playGame('rock');"><img src="rock.jpg" alt="rock" /></td>
<td rowspan="3"><img id="leftHand" src="leftPaperHand.jpg" alt="leftHandPaper" /></td>
<td rowspan="3"><img id="rightHand" src="rightRockHand.jpg" alt="rightHandRock"/></td>
</tr>
<tr>
<td onclick="playGame('paper');"><img src="paper.jpg" alt="paper" /></td>
</tr>
<tr>
<td onclick="playGame('scissors');"><img src="scissors.jpg" alt="scissors" /></td>
</tr>
<tr>
<td colspan="3"><p>Wins: Losses: Ties:</p></td>
</tr>
</table>
<script type="text/javascript">
picForLeftPlayer = "leftPaperHand.jpg";
picForRightPlayer = "rightRockHand.jpg";
function playGame (choice){
switch (choice){
case 'rock':
document.getElementById("leftHand").src="leftRockHand.jpg";
case 'paper':
document.getElementById("leftHand").src="leftPaperHand.jpg";
case 'scissors':
document.getElementById("leftHand").src="leftScissorsHand.jpg";
}
}
</script>
Rock Paper Scissors in Javascript
Page 1 of 12 Replies - 1352 Views - Last Post: 05 April 2012 - 04:22 PM
#1
Rock Paper Scissors in Javascript
Posted 05 April 2012 - 12:47 PM
I am trying to create a simple Javascript game of Rock Paper Scissors and I just need help with one quick thing. I need to make it so that when the user clicks the image of either rock paper or scissors, the image of the hand (a different image) changes to mimic what they clicked. Below is the code for just changing the image, for some reason the image will not show up. Please help. Thanks!
Replies To: Rock Paper Scissors in Javascript
#2
Re: Rock Paper Scissors in Javascript
Posted 05 April 2012 - 04:16 PM
You're missing a break after each case statement:
<table>
<tr>
<td colspan="3">Rock Paper Scissors</td>
</tr>
<tr>
<td onclick="playGame('rock');"><img src="rock.jpg" alt="rock" /></td>
<td rowspan="3"><img id="leftHand" src="leftPaperHand.jpg" alt="leftHandPaper" /></td>
<td rowspan="3"><img id="rightHand" src="rightRockHand.jpg" alt="rightHandRock"/></td>
</tr>
<tr>
<td onclick="playGame('paper');"><img src="paper.jpg" alt="paper" /></td>
</tr>
<tr>
<td onclick="playGame('scissors');"><img src="scissors.jpg" alt="scissors" /></td>
</tr>
<tr>
<td colspan="3"><p>Wins: Losses: Ties:</p></td>
</tr>
</table>
<script type="text/javascript">
picForLeftPlayer = "leftPaperHand.jpg";
picForRightPlayer = "rightRockHand.jpg";
function playGame (choice){
switch (choice){
case 'rock':
document.getElementById("leftHand").src="leftRockHand.jpg";
break;
case 'paper':
document.getElementById("leftHand").src="leftPaperHand.jpg";
break;
case 'scissors':
document.getElementById("leftHand").src="leftScissorsHand.jpg";
break;
}
}
</script>
#3
Re: Rock Paper Scissors in Javascript
Posted 05 April 2012 - 04:22 PM
THANK YOU!!!!!
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|