Skip to content

Instantly share code, notes, and snippets.

@jhgaylor
Forked from Kithari/gist:e6691ba6a55f15974569
Last active November 22, 2015 07:31
Show Gist options
  • Save jhgaylor/84ce4d719d5b8f168e55 to your computer and use it in GitHub Desktop.
Save jhgaylor/84ce4d719d5b8f168e55 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";
}
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);
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!";
}
}
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