Advertisement
yo2man

Rock/Paper/Scissors What am I doing wrong?

May 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Rock, Paper, Scissors
  2.  
  3. //Prompt for choice:
  4. var userChoice = prompt("Do you choose rock, paper or scissors?");
  5.  
  6. console.log("Your choice: " + userChoice);
  7.  
  8. //Computer plays:
  9. var computerChoice = Math.random();
  10. if (computerChoice < 0.34) {
  11.     computerChoice = "rock";
  12. } else if(computerChoice <= 0.67) {
  13.     computerChoice = "paper";
  14. } else {
  15.     computerChoice = "scissors";
  16. }
  17. //log the choice
  18. console.log("Computer choice: " + computerChoice);
  19.  
  20.  
  21.  
  22. //Choice results
  23. var compare = function(choice1, choice2) {
  24.     if (choice1 == choice2) {
  25.     return "The result is a tie!";
  26.     }
  27.    
  28.     //userChoice: rock
  29.     else if (choice1 == "rock"){
  30.         if(choice2 == "scissors"){
  31.             return console.log("rock wins!");
  32.         }
  33.         else{
  34.             return "paper wins";
  35.         }
  36.     }    
  37.    
  38.     //userChoice: paper
  39.     else if (choice1 == "paper") {
  40.         if(choice2 == "rock"){
  41.             return "paper wins";
  42.         }
  43.         else{
  44.             return "scissors wins";
  45.         }
  46.     }
  47.    
  48.     //userChoice: scissors
  49.     else{
  50.         if(choice2 = "rock"){
  51.             return "rock wins";
  52.         }
  53.         else{
  54.             return "scissors wins";
  55.         }
  56.     }
  57.   }
  58.  
  59. compare(userChoice, computerChoice);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement