Last active
February 23, 2016 23:05
-
-
Save anonymous/d244f5963d4f6ea09aac 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 = ["paper", "rock", "scissors"]; | |
var computerChoice = Math.random(); | |
if (computerChoice < 0.34) { | |
computerChoice = userChoice[1]; | |
} else if(computerChoice <= 0.67) { | |
computerChoice = userChoice[0]; | |
} else { | |
computerChoice = userChoice[2]; | |
} console.log("Computer: " + computerChoice); | |
var compare= function (choice1, choice2) { | |
if (choice1 === choice2) { | |
return "The result is a tie!"; | |
} | |
else if (choice1===userChoice[1]) { | |
if (choice2===userChoice[2]) { | |
return "You win!"; | |
} | |
else { | |
return "You lose!"; | |
} | |
} else if (choice1===userChoice[0]) { | |
if (choice2===userChoice[1]) { | |
return "You win!"; | |
} else { | |
return "You lose!" | |
} | |
} else if (choice1===userChoice[2]) { | |
if (choice2===userChoice[0]) { | |
return "You win!"; | |
} else { | |
return "You lose!"; | |
}; | |
}; | |
}; | |
var result = compare(userChoice, computerChoice); | |
console.log(result); | |
var play(1)=function(userChoice) { | |
document.getElementById('computer-choice').innerHTML = computerChoice; | |
document.getElementById('user-choice').innerHTML = userChoice[0]; | |
document.getElementById('result').innerHTML = result; | |
}; | |
var play(2)=function(userChoice) { | |
document.getElementById('computer-choice').innerHTML = computerChoice; | |
document.getElementById('user-choice').innerHTML = userChoice[1]; | |
document.getElementById('result').innerHTML = result; | |
}; | |
var play(3)=function(userChoice) { | |
document.getElementById('computer-choice').innerHTML = computerChoice; | |
document.getElementById('user-choice').innerHTML = userChoice[2]; | |
document.getElementById('result').innerHTML = result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment