Skip to content

Instantly share code, notes, and snippets.

@dariye
Created September 23, 2013 18:27
Show Gist options
  • Save dariye/6674787 to your computer and use it in GitHub Desktop.
Save dariye/6674787 to your computer and use it in GitHub Desktop.
A Pen by paul.
//user input
var userChoice = function () {
var choice = prompt("Rock, Paper, Scissors...?");
if (choice === "rock" || choice === "paper" || choice === "scissors") {
return choice;
}
else {
choice = prompt("Wrong choice! Now to play enter rock, paper, or scissors...");
return choice;
}
};
//computer generated choice
var computerChoice = function () {
var choice = Math.random(0, 1);
if (choice <= 0.33 ) {
choice = "rock";
}
else if (choice > 0.33 && choice <= 0.67) {
choice = "paper";
}
else {
choice = "scissors";
}
return choice;
};
//compare and and select winner
var compare = function(choice1, choice2) {
/* if (choice1 === choice2) {
return "it's a tie";
}*/
if (choice1 === "rock") {
if (choice2 === "paper" ) {
return "too bad! the computer(paper) had the best of ya! Go ahead and sob...lol";
}
else {
return "yay!, you(rock) win";
}
}
else if (choice1 === "paper") {
if (choice2 === "rock" ) {
return "yay!, you(paper) win";
}
else {
return "too bad! the computer(scissors) had the best of ya! Go ahead and sob...lol";
}
}
else if (choice1 === "scissors" ) {
if (choice2 === "paper" ) {
return "yay!, you(scissors) win";
}
else {
return "too bad! the computer(rock) had the best of ya! Go ahead and sob...lol";
}
}
else {
return "it's a tie!"
}
};
var rockPaperScissors = function() {
//take user input from userChoice() and take computer choice from computerChoice();
//analyze
if(confirm("are you ready to play Rock, Paper, Scissors?")) {
alert(compare(userChoice(), computerChoice()));
}
else {
alert("Ok, go ahead and be boring!");
}
};
rockPaperScissors();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment