TicTacToe

jsdbf

by Will Stott

JavaScript

var playAgain = true;
while (playAgain) {
var userChoice = prompt("Please type in rock, or paper, or scissors.", "Type it here!");

while(userChoice != "rock" && userChoice != "paper" && userChoice != "scissors") {
    userChoice = prompt("Uh oh! You plonker, I didn't understand '"+userChoice+"'! Please type in rock, or paper, or scissors.", "Type it here!");
}
var computerChoice = Math.floor(Math.random()*3);
if (userChoice == "rock") {
    if (computerChoice == 0) {
        alert("Draw!");
    } else if (computerChoice == 1) {
        alert("Lost!");
    } else if (computerChoice == 2) {
        alert("Won!");
    }
} else if (userChoice == "paper") {
    if (computerChoice == 0) {
        alert("Won!");
    } else if (computerChoice == 1) {
        alert("Draw!");
    } else if (computerChoice == 2) {
        alert("Lost!");
    }
} else if (userChoice == "scissors") {
    if (computerChoice == 0) {
        alert("Lost!");
    } else if (computerChoice == 1) {
        alert("Won!");
    } else if (computerChoice == 2) {
        alert("Draw!");
    }
}
playAgain = confirm("Would you like to play again?");
}