Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 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. var compare = function (choice1,choice2)
  11. {
  12. if (choice1 === choice2)
  13. {
  14. return "The result is a tie!"
  15. }
  16. else if (choice1 === "rock")
  17. {
  18. if (choice2 === "scissors")
  19. {
  20. return "rock wins"
  21. }
  22. else
  23. {
  24. return "paper wins"
  25. }
  26. }
  27. else if (choice1 === "paper")
  28. {
  29. if (choice2 === "rock")
  30. {
  31. return "paper wins"
  32. }
  33. else
  34. {
  35. return "scissors wins"
  36. }
  37. }
  38. else
  39. {
  40. if (choice2 === "paper")
  41. {
  42. return "scissors wins"
  43. }
  44. else
  45. {
  46. return "rock wins"
  47. }
  48. }
  49. }
  50. compare(userChoice,computerChoice);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement