Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 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.  
  16.  
  17.  
  18.  
  19. else if(choice1 === "rock") {
  20.  
  21. if(choice2 === "scissors") {
  22. return "rock wins";
  23. }
  24. else {
  25. return "paper wins";
  26. }
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. else if(choice1 === "paper") {
  34. if(choice2 === rock) {
  35. return "paper wins";
  36. }
  37. else {
  38. return "scissors wins";
  39. }
  40. }
  41.  
  42.  
  43.  
  44.  
  45. else if(choice1 === "scissors") {
  46. if(choice2 === rock) {
  47. return "rock wins";
  48. }
  49. else {
  50. return "scissors wins";
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement