# Next Steps - Rock, Paper, Scissors, Lizard, Spock

Rock, Paper, Scissors, Lizard, Spock

Here is my simple extension to the Rock Paper Scissors game which you can play here: Codecademy Labs
Try it and tell me what you think!

I have implemented the four challenges posed in âNext Stepsâ:
Q1) What if a user makes an inappropriate choice like âdogâ?
Q2) How would it be valuable to wrap the entire game in one function?
Q3) What if players in the game could also choose Rope in this game?
Q4) What if the game didnât with a tie but instead asked both players for new choices?

For Q3 it is impossible to have a fair game with only four choices so I went with 5. The rules for this game are based on an episode of The Big Bang Theory.
Also I found this website based on this game: RPSLS Online game

```

/* Game rules are as follows:
* Scissors cut paper
* Paper covers rock
* Rock crushes lizard
* Lizard poisons Spock
* Spock smashes scissors
* Scissors decapitate lizard
* Lizard eats paper
* Paper disproves Spock
* Spock vaporizes rock
* Rock crushes scissors
*/

//Intro
confirm(âTry and beat the computer at Rock, Paper, Scissors, Lizard, Spock!â);

//Wraps entire game in one function (ANSWERS Q2)
var game = function() // âgameâ function starts here
{
//ârpslsâ function contains logic to determine the result
var rpsls = function(choice1, choice2)
{
//If user and computerâs choices match (ANSWERS Q4)
if (choice1 === choice2)
{
}
//If user picks ROCK
else if (choice1 == ârockâ)
{
if (choice2 === âpaperâ)
{alert (âYOU LOSE! (paper covers rock)â);}
else if (choice2 === âscissorsâ)
{alert (âYOU WIN! (rock crushes scissors)â);}
else if (choice2 === âlizardâ)
{alert (âYOU WIN! (rock crushes lizard)â);}
else //Computer must have chosen spock
{alert (âYOU LOSE! (spock vaporises rock)â);}
}
//If user picks PAPER
else if (choice1 === âpaperâ)
{
if (choice2 === ârockâ)
{alert (âYOU WIN! (paper covers rock)â);}
else if (choice2 === âscissorsâ)
{alert (âYOU LOSE! (scissors cut paper)â);}
else if (choice2 === âlizardâ)
{alert (âYOU LOSE! (lizard eats paper)â);}
else //Computer must have chosen spock
{alert (âYOU WIN! (paper disproves spock)â);}
}
//If user picks SCISSORS
else if (choice1 === âscissorsâ)
{
if (choice2 === ârockâ)
{alert (âYOU LOSE! (rock crushes scissors)â);}
else if (choice2 === âpaperâ)
{alert (âYOU WIN! (scissors cut paperâ);}
else if (choice2 === âlizardâ)
{alert (âYOU WIN! (scissors decapitate lizard)â);}
else //Computer must have chosen spock
{alert (âYOU LOSE! (spock smashes scissors)â);}
}
//If user picks LIZARD
else if (choice1 === âlizardâ)
{
if (choice2 === ârockâ)
{alert (âYOU LOSE! (rock crushes lizard)â);}
else if (choice2 === âpaperâ)
{alert (âYOU WIN! (lizard eats paper)â);}
else if (choice2 === âscissorsâ)
{alert (âYOU LOSE! (scissors decapitate lizard)â);}
else //Computer must have chosen spock
{alert (âYOU WIN! (lizard poisons spock)â);}
}
//User must have picked SPOCK
else
{
if (choice2 === ârockâ)
{alert (âYOU WIN! (spock vaporises rock)â);}
else if (choice2 === âpaperâ)
{alert (âYOU LOSE! (paper disproves spockâ);}
else if (choice2 === âscissorsâ)
{alert (âYOU WIN! (spock smashes scissors)â);}
else //Computer must have chosen lizard
{alert (âYOU LOSE! (lizard poisons spock)â);}
}
};

``````//Players choose
var userChoice = prompt("Do you choose rock, paper, scissors, lizard or spock?");
//If user doesn't pick one of the options (ANSWERS Q1)
if (userChoice !== "rock" && userChoice !== "paper" && userChoice !== "scissors" && userChoice !== "lizard" && userChoice !== "spock")
{
alert ("You need to pick one of the five choices.");
} else {

var computerChoice = Math.random();
if (computerChoice <=0.20)
{computerChoice = "rock";}
else if(computerChoice <=0.40)
{computerChoice = "paper";}
else if(computerChoice <=0.60)
{computerChoice = "scissors";}
else if(computerChoice <=0.80)
{computerChoice = "lizard";}
else
{computerChoice = "spock";}

console.log("You chose " + userChoice + " & the computer chose " + computerChoice);

rpsls(userChoice,computerChoice);
}

//Choice to play again
var choice = prompt("Play again? 'yes' or 'no'");
var playagain = function (choice)
{
if (choice === "yes")
{
game(); //Replays the game
} else {
``<do not remove the three backticks above>``