My game works fine except when I win when lizard or spock is involved, I can't figure out why because when I lose it displays that I lose which is correct. I tried to look for typos but couldn't find any. If anyone can see what's wrong I'd appreciate it.
Here is a fiddle so you can see the problem: http://jsfiddle.net/5RGwv/
Here is my HTML:
<div id="center">
<button id="button" onclick="play()">Play</button>
<p>You rolled:</p><span id="myroll"></span>
<p>Your opponent rolled:</p><span id="opproll"></span>
<p id="outcome"></p>
</div>
Javascript:
function play() {
var ROCK = 0;
var PAPER = 1;
var SCISSORS = 2;
var LIZARD = 3;
var SPOCK = 4;
var choices = ['rock', 'paper', 'scissors', 'lizard', 'spock'];
var myRoll = Math.floor(Math.random()*choices.length);
var opponentRoll = Math.floor(Math.random()*choices.length);
document.getElementById("myroll").innerHTML=choices[myRoll];
document.getElementById("opproll").innerHTML=choices[opponentRoll];
if (myRoll == opponentRoll) {
document.getElementById("outcome").innerHTML="It's a draw.";
return;
} //end of if
switch(myRoll) {
case ROCK:
document.getElementById("outcome").innerHTML=(opponentRoll == SCISSORS ? 'You win!' : 'You lose!');
return;
case ROCK:
document.getElementById("outcome").innerHTML=(opponentRoll == LIZARD ? 'You win!' : 'You lose!');
return;
case PAPER:
document.getElementById("outcome").innerHTML=(opponentRoll == ROCK ? 'You win!' : 'You lose!');
return;
case PAPER:
document.getElementById("outcome").innerHTML=(opponentRoll == SPOCK ? 'You win!' : 'You lose!');
return;
case SCISSORS:
document.getElementById("outcome").innerHTML=(opponentRoll == PAPER ? 'You win!' : 'You lose!');
return;
case SCISSORS:
document.getElementById("outcome").innerHTML=(opponentRoll == LIZARD ? 'You win!' : 'You lose!');
return;
case LIZARD:
document.getElementById("outcome").innerHTML=(opponentRoll == SPOCK ? 'You win!' : 'You lose!');
return;
case LIZARD:
document.getElementById("outcome").innerHTML=(opponentRoll == PAPER ? 'You win!' : 'You lose!');
return;
case SPOCK:
document.getElementById("outcome").innerHTML=(opponentRoll == SCISSORS ? 'You win!' : 'You lose!');
return;
case SPOCK:
document.getElementById("outcome").innerHTML=(opponentRoll == ROCK ? 'You win!' : 'You lose!');
return;
} //end of switch(myRoll)
} //end of play()