# Thread: Would you help a complete beginner? (rock-paper-scissors-lizard-spock game)

1. SHa
Registered User
Join Date
Jan 2014
Posts
1

## Would you help a complete beginner? (rock-paper-scissors-lizard-spock game)

Hello!
i just started to learn Javascript and i tried to write a rock - paper - scissors - lizard - Spock game,
it doesn't return the right answers.
what have i done wrong? the nesting? the math.random()?

here's the code:

var userChoice = prompt("Do you choose rock, paper, scissors, lizard or spock?");
var computerChoice = Math.random();
console.log(computerChoice);
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)
computerChoise = "lizard";
else
if(computerChoice <= 1)
computerChoice = "spock";

var compare = function(choice1 , choice2){
if (choice1 == choice2)
return("The result is a tie!");

else
if (choice1 == "rock")
if (choice2 == "scissors")
return("rock wins");
else
if(choise2 == "paper")
return("paper wins");
else
if(choice2 == "lizard")
return("rock wins");
else
if(choice2 == "spock")
return ("spock wins");
else
if (choice1 == "paper")
if (choice2 == "rock")
return("paper wins");
else
if(choice2 == "scissors")
return("scissors wins");
else
if(choice2 == "lizard")
return ("lizard wins");
else
if(choice2 == "spock")
return("paper wins");
else
if (choice1 == "scissors")
if (choice2 == "rock")
return("rock wins");
else
if(choice2 == "paper")
return("scissors wins");
else
if(choice2 == "lizard")
return("scissors wins");
else
if(choice2 == "spock")
return("spock wins");
else
if (choice1 == "lizard")
if (choice2 == "rock")
return("rock wins");
else
if(choice2 == "paper")
return("lizard wins");
else
if(choice2 == "scissors")
return("scissors wins");
else
if(choice2 == "spock")
return("lizard wins");
else
if (choice1 == "spock")
if (choice2 == "rock")
return("spock wins");
else
if(choice2 == "paper")
return("paper wins");
else
if(choice2 == "lizard")
return("lizard wins");
else
if(choice2 == "scissors")
return("spock wins");
};

compare(computerChoice, userChoice);

2. I have always hated the answers like the one I'm going to give to you but the fact that this issue (making rock-paper-scissors game) was already discussed many times before I would suggest you use the search function of the forum.

3. Yep, not the first, nor the last and in the spirit of the great Spock, go forth and you will find what you seek.