-
-
Save jhgaylor/84ce4d719d5b8f168e55 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"; | |
} | |
else if((computerChoice > 0.33) && (computerChoice<0.67)){ | |
computerChoice = "scissors"; | |
} | |
// never do an if/else without {}. It's a lie that it is is allowed. NO! Just don't do it! It's like cake. | |
else { | |
computerChoice = "paper"; | |
} | |
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!"; | |
} | |
else if(choice1==="paper"){ | |
if(choice2==="rock"){ | |
return "Paper wins!"; | |
} | |
else return "Scissors wins!"; | |
} | |
else if(choice1==="scissors"){ | |
if(choice1==="paper"){ | |
return "Scissors wins!"; | |
} | |
else return "Paper wins!"; | |
} | |
} | |
compare(userChoice, computerChoice); |
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"; | |
} | |
else if((computerChoice > 0.33) && (computerChoice<0.67)){ | |
computerChoice = "scissors"; | |
} | |
// never do an if/else without {}. It's a lie that it is is allowed. NO! Just don't do it! It's like cake. | |
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!"; | |
} | |
else if(choice1==="paper"){ | |
if(choice2==="rock"){ | |
return "Paper wins!"; | |
} | |
else return "Scissors wins!"; | |
} | |
else if(choice1==="scissors"){ | |
if(choice1==="paper"){ | |
return "Scissors wins!"; | |
} | |
else return "Paper wins!"; | |
} | |
} |
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"; | |
} | |
else if((computerChoice > 0.33) && (computerChoice<0.67)){ | |
computerChoice = "scissors"; | |
} | |
// never do an if/else without {}. It's a lie that it is is allowed. NO! Just don't do it! It's like cake. | |
else { | |
computerChoice = "paper"; | |
} | |
compare(userChoice, computerChoice); | |
function compare(choice1, choice2){ | |
if(choice1 === choice2){ | |
return "Game is a tie"; | |
} | |
else if(choice1 === "rock"){ | |
if(choice2 === "paper"){ | |
return "Paper wins!"; | |
} | |
else return "Rock wins!"; | |
} | |
else if(choice1==="paper"){ | |
if(choice2==="rock"){ | |
return "Paper wins!"; | |
} | |
else return "Scissors wins!"; | |
} | |
else if(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