Advertisement
Guest User

rock paper scissors

a guest
Sep 1st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 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. } console.log("Computer: " + computerChoice);
  10.  
  11. var compare = function(choice1, choice2) {
  12. if(choice1 === choice2) {
  13. return "The result is a tie";
  14. }
  15. else if(choice1 === "paper") {
  16. if(choice2 === "rock") {
  17. return "paper wins"
  18. }
  19. else {
  20. return "scissors win"
  21. }
  22. }
  23.  
  24. else if(choice1 === "rock") {
  25.  
  26. if(choice2 === "scissors") {
  27. return "rock wins";
  28. }
  29. else {
  30. return "paper wins";
  31. }
  32.  
  33. }
  34. else {
  35. if(choice2 === "rock") {
  36. return "rock wins"
  37. }
  38. else {
  39. return "scissors win"
  40. }
  41. }
  42. };
  43. compare(userChoice, computerChoice)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement