User:Titusfox/RPSLS

<!DOCTYPE html> Rock, paper, scissors, lizard, SPOCK! 

function gameCode {

var mychoices = []; var defeatedby = ""; var userChoice = ""; var userScore = 0; var computerChoice = ""; var computerScore = 0; var myIndex = 0; var myMessage = ""; //initialise choices mychoices = ["rock","spock","paper","lizard","scissors"];

//initialise outcomes defeatedby = ["spockpaper","paperlizard","lizardscissors","scissorsrock","rockspock"] //Start main loop do { //input user choice userChoice = prompt("Do you want Rock, Paper, Scissors, Lizard or Spock?"); userChoice = userChoice.toLowerCase; // computer selects a random choice computerChoice = mychoices[Math.floor(Math.random * mychoices.length)]; computerChoice = computerChoice.toLowerCase; // set default reply as not a valid choice myMessage = "Thats not valid"; // check for a tie if (userChoice == computerChoice) { myMessage = "Its a tie!"; } else { // initialise index myIndex = 0; // loop through choices while (myIndex < mychoices.length) { //check who wins if (mychoices[myIndex] == userChoice) { if (defeatedby[myIndex].indexOf(computerChoice,0) == -1) { //user wins myMessage=userChoice+" beats "+computerChoice+", you win"; userScore++; } else { //computer wins myMessage=computerChoice+" beats "+userChoice+", I win"; computerScore++; }				}				// increment index myIndex++; }		}		// display result alert (myMessage); //Ask if user want to play again } while (confirm("Do you want to play again?")); // end of main loop //Display scores alert ("User score="+userScore.toString+", Computer Score="+computerScore.toString); }

Welcome to Rock, paper lizard, scissors, Spock  Click to play! Just a JS Example