Advertisement
Guest User

penis

a guest
Jan 6th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var userStartFunc = function(){
  2.     var userChoice = prompt("Do you choose rock, paper or scissors?");
  3.     return userChoice
  4. }
  5. var computerStartFunc = function(){
  6.     var computerChoice = Math.random();
  7.     if (computerChoice < 0.34) {
  8.         computerChoice = "rock";
  9.     }
  10.     else if(computerChoice <= 0.67) {
  11.         computerChoice = "paper";
  12.     }
  13.     else {
  14.         computerChoice = "scissors";
  15.     }
  16.     return computerChoice;
  17. }
  18.  
  19. var compare = function(choice1, choice2){
  20.     if(choice1 == "rock"){
  21.         if(choice2 == "scissors"){
  22.             return "rock wins";    
  23.         }    
  24.         else{
  25.             return "paper wins";
  26.         }
  27.     }
  28.     else if(choice1 == "paper"){
  29.         if(choice2 == "rock"){
  30.             return "paper wins";    
  31.         }    
  32.         else{
  33.             return "scissors wins";
  34.         }
  35.     }
  36.     else if(choice1 == "scissors"){
  37.         if(choice2 == "rock"){
  38.             return "rock wins";    
  39.         }    
  40.         else{
  41.             return "scissors wins";
  42.         }
  43.     }
  44. }
  45. var endFunc = function(userChoice, computerChoice){
  46.     if(userChoice == "rock" || userChoice == "scissors" || userChoice == "paper"){
  47.         var endResult = compare(userChoice, computerChoice);
  48.         document.write("Computer choice: "+computerChoice+"<br>");
  49.         document.write("Your choice: "+userChoice+"<br>");
  50.         document.write(endResult+"<br>");
  51.     }
  52.     else{
  53.         document.write("Bad choice! This is impossible!");
  54.     }
  55. }
  56. var i = 0;
  57. var status = 1;
  58. do{
  59.     userChoice = userStartFunc();
  60.     computerChoice = computerStartFunc();
  61.     if(userChoice == computerChoice && status != 1){
  62.         document.write("The result is a tie!");
  63.         i = 0;
  64.     }
  65.     else{
  66.         endFunc(userChoice, computerChoice);
  67.         i = 1;
  68.     }
  69.     status = 2;
  70. }while(i == 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement