Skip to content

Instantly share code, notes, and snippets.

@TehNut
Created November 14, 2014 04:35
Show Gist options
  • Save TehNut/255fac2af3e92c06e705 to your computer and use it in GitHub Desktop.
Save TehNut/255fac2af3e92c06e705 to your computer and use it in GitHub Desktop.
It's rock paper scissors... Yay!
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "Rock";
} else if(computerChoice <= 0.67) {
computerChoice = "Paper";
} else {
computerChoice = "Scissors";
}
console.log("Player: " + userChoice)
console.log("Computer: " + computerChoice);
var compare = function(userInput, computerInput) {
if (userInput == computerInput) {
return "The result is a tie!";
} else if (userInput == "Rock") {
if (computerInput == "Scissors") {
return "Rock wins";
} else if (computerInput == "Paper") {
return "Paper wins";
}
} else if (userInput == "Paper") {
if (computerInput == "Rock") {
return "Paper wins";
} else if (computerInput == "Scissors") {
return "Scissors wins";
}
} else if (userInput == "Scissors") {
if (computerInput == "Paper") {
return "Scissors wins";
} else if (computerInput == "Rock") {
return "Rock wins";
}
}
}
console.log(compare(userChoice, computerChoice))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment