Created
July 8, 2016 03:07
-
-
Save tebba-von-mathenstein/40384c356907881b039aea7f03772e91 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
// Get the user's choice | |
var userChoice = prompt("Rock, paper, or scissors?"); | |
userChoice = userChoice.toLowerCase(); | |
// Get the computer's choice | |
var computerChoice = Math.random(); | |
// Teach the computer how to guess rock, paper, or scissors | |
if(computerChoice < .33) { | |
computerChoice = "rock"; | |
} | |
else if(computerChoice < .66) { | |
computerChoice = "paper"; | |
} | |
else { | |
computerChoice = "scissors"; | |
} | |
// Compare their choices and tell the user the result | |
if(computerChoice === userChoice) { | |
alert("its a tie! you both chose " + userChoice); | |
} | |
else { | |
if(userChoice === "rock") { | |
if(computerChoice === "scissors") { | |
alert("The user wins! Rock beats scissors"); | |
} | |
else if(computerChoice === "paper") { | |
alert("The User Loses! paper beats rock"); | |
} | |
} | |
else if(userChoice === "scissors") { | |
if(computerChoice === "rock") { | |
alert("The user loses! rock beats scissors"); | |
} | |
else if(computerChoice === "paper") { | |
alert("The User Wins! scissors beats paper"); | |
} | |
} | |
else if(userChoice === "paper") { | |
if(computerChoice === "scissors") { | |
alert("The user loses! scissorz beats paper"); | |
} | |
else if(computerChoice === "rock") { | |
alert("The User Wins! paper beats rock"); | |
} | |
} | |
else { | |
alert("the user made an invalid choice"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment