Advertisement
Crenox

Rock, Paper, Scissors Game Javascript

Dec 9th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. var userChoice = prompt("Do you choose rock, paper or scissors?");
  2. var computerChoice = Math.random();
  3. if (computerChoice <0.34){
  4. computerChoice = "rock";
  5. }else if(computerChoice <=0.67){
  6. computerChoice = "paper";
  7. }else{
  8. computerChoice = "scissors";
  9. }
  10. var compare = function(choice1,choice2){
  11.  
  12. if(choice1 === choice2) return "The result is a tie!";
  13.  
  14. if(choice1 === "rock") {
  15.  
  16. if(choice2 === "scissors") {
  17.  
  18. return "rock wins";}
  19.  
  20. else{
  21.  
  22. return "paper wins";
  23.  
  24. }
  25. }
  26. if (choice1 === "paper") {
  27.  
  28. if (choice2 === "rock") {
  29.  
  30. return ("paper wins");}
  31.  
  32. else{
  33.  
  34. return ("scissors win");
  35.  
  36. }
  37. }
  38. if (choice1 === "scissors") {
  39.  
  40. if (choice2 === "paper") {
  41.  
  42. return ("scissors wins");}
  43.  
  44. else{
  45.  
  46. return ("rock wins");
  47.  
  48. }
  49. }
  50. };
  51.  
  52. compare(userChoice, computerChoice);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement