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!";
}
}