Created
November 22, 2015 07:24
-
-
Save Kithari/e6691ba6a55f15974569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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