Skip to content

Instantly share code, notes, and snippets.

@Kithari
Created November 22, 2015 07:24
Show Gist options
  • Save Kithari/e6691ba6a55f15974569 to your computer and use it in GitHub Desktop.
Save Kithari/e6691ba6a55f15974569 to your computer and use it in GitHub Desktop.
var userChoice = prompt("Please choose rock, paper, or scissors");
var computerChoice = Math.random();
if(computerChoice >=0 && computerChoice<0.33){
computerChoice = "rock"
}
elseif(computerChoice >0.33 && computerChoice<0.67){
computerChoice = "scissors"
}
else computerChoice = "paper"
compare(userChoice, computerChoice)
var compare = function(choice1, choice2){
if(choice1 === choice2){
return "Game is a tie"
}
elseif(choice1 === "rock"){
if(choice2 === "paper"){
return "Paper wins!"
}
else return "Rock wins!"
}
elseif(choice1==="paper"){
if(choice2==="rock"){
return "Paper wins!"
}
else return "Scissors wins!"
}
elseif(choice1==="scissors"){
if(choice1==="paper"){
return "Scissors wins!"
}
else return "Paper wins!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment