SO - 17646045
by Arun P Johny
JavaScript
var myChoice = "";
var compChoice = "";
var again;
do
{
myChoice = prompt("Do you choose rock, paper or scissors?");
compChoice = Math.random();
if (compChoice < 0.33) {
compChoice == "rock";
} else if(compChoice < 0.67) {
compChoice = "paper";
} else {
compChoice == "scissors";
}
if (compChoice == myChoice) {
alert("It's a tie!");
} else if (compChoice == "rock") {
if(myChoice == "scissors") {
alert("You lose!");
} else if (myChoice == "paper") {
alert("You win!");
}
} else if (compChoice == "paper") {
if (myChoice == "rock") {
alert("You lose!");
} else if (myChoice == "scissors") {
alert("You win!");
}
} else if (compChoice == "scissors") {
if (myChoice == "rock") {
alert("You win!");
} else if (myChoice == "paper") {
alert("You lose!");
}
}
again = prompt("Would you like to play again?(yes/no)");
}while (again == "yes");