Rock Paper Scissors

HTML
<!DOCTYPE html> <button onClick="rock()">Rock</button> <button onClick="paper()">Paper</button> <button onClick="scissors()">Scissors</button> <p id="selection"></p> <p id="rps"></p> <p id="result"></p>
CSS
JAVASCRIPT
var options = ["Rock", "Paper", "Scissors"]; //rock() function rock() { var rps = options[Math.floor(Math.random() * options.length)]; document.getElementById("selection").innerHTML = "You picked Rock!"; document.getElementById("rps").innerHTML = "I picked " + rps + "!"; if(rps === 'Rock') { document.getElementById("result").innerHTML = "It's a draw!"; } else if(rps === 'Scissors'){ document.getElementById("result").innerHTML = "Rock smashes scissors; You win!"; } else { document.getElementById("result").innerHTML = "Paper covers rock; I win!"; } } //paper() function paper() { var rps = options[Math.floor(Math.random() * options.length)]; document.getElementById("selection").innerHTML = "You picked Paper!"; document.getElementById("rps").innerHTML = "I picked " + rps + "!"; if(rps === 'Paper') { document.getElementById("result").innerHTML = "It's a draw!"; } else if(rps === 'Scissors'){ document.getElementById("result").innerHTML = "Scissors cut paper; I win!"; } else { document.getElementById("result").innerHTML = "Paper covers rock; You win!"; } } //scissors() function scissors() { var rps = options[Math.floor(Math.random() * options.length)]; document.getElementById("selection").innerHTML = "You picked Scissors!"; document.getElementById("rps").innerHTML = "I picked " + rps + "!"; if(rps === 'Scissors') { document.getElementById("result").innerHTML = "It's a draw!"; } else if(rps === 'Rock'){ document.getElementById("result").innerHTML = "Rock smashes scissors; I win!"; } else { document.getElementById("result").innerHTML = "Scissors cut paper; You win!"; } }
Expand for more options Login