Skip to content

Instantly share code, notes, and snippets.

@crissyg
Last active July 19, 2017 14:23
Show Gist options
  • Save crissyg/17f4c1d6d8e1ea145931 to your computer and use it in GitHub Desktop.
Save crissyg/17f4c1d6d8e1ea145931 to your computer and use it in GitHub Desktop.
Simple Rock Paper Scissors game using a confirmation box
<html>
<head>
<SCRIPT LANGUAGE="JavaScript"> ;
// Rock , Paper, Scissors Game
// prompt user to choose
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random(); // variable = to # between 0 and 1
// to see how mathrandom works-- print out math.random
// should show 0.08906989803345089 to console
console.log(computerChoice)
console.log("Computer Choice:")
if(computerChoice >=0 & computerChoice <=0.33){
computerChoice = "rock";
confirm("computer choice: rock");
}
else if(computerChoice >=0.34 & computerChoice <=0.66 ){
computerChoice = "paper";
confirm("computer choice: paper");
}
else
{
computerChoice = "scissors";
confirm("computer choice: scissors");
}
/*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";
}*/
</script>
<title>Rock,Paper or Scissors </title>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment