Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var userChoice = "";
- var computerChoice = "";
- var translate = 0;
- var noWinner = true;
- function verifyChoice(a){
- if((a === "rock") || (a === "paper") || (a === "scissors")){
- return 0;
- }
- else {
- return 1;
- }
- };
- function computerRandom(){
- translate = Math.random();
- if(translate < 0.34){
- return "rock";
- }
- else if(translate <= 0.67){
- return "paper";
- }
- else{
- return "scissors";
- }
- };
- //returns true if choice wins
- function compare(choice, computerChoice){
- if ((choice === "rock" && computerChoice === "scissors")||
- (choice === "paper" && computerChoice === "rock")||
- (choice === "scissors" && computerChoice === "paper")){
- return 1;
- } else {
- return 0;
- }
- };
- do{
- userChoice = prompt("Do you choose rock, paper or scissors?");
- if(verifyChoice(userChoice)){
- computerChoice = computerRandom();
- confirm("Computer chose: " + computerChoice);
- if(computerChoice === userChoice){
- confirm("It's a tie! Try again!");
- }else if(compare(userChoice,computerChoice)){
- confirm("You win!");
- noWinner = false;
- }else{
- confirm("Computer wins, you suck!");
- noWinner = false;
- }
- }else{
- confirm("That is not a valid option");
- }
- }while(noWinner);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement