Advertisement
askarulytarlan

Rock,Paper or Scissors. Game

Jan 4th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 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. if (choice1 === choice2){
  12. return "The result is a tie!";
  13. }
  14. if (choice1 === "rock"){
  15. if (choice2 === "scissors"){
  16. return "rock wins";
  17. } else {
  18. return "paper wins";
  19. }
  20. }
  21. if (choice1 === "paper"){
  22. if (choice2 === "rock"){
  23. return "paper wins";
  24. } else {
  25. return "scissors wins";
  26. }
  27. }
  28. if (choice1 === "scissors"){
  29. if (choice2 === "paper"){
  30. return "scissors wins";
  31. } else {
  32. return "rock wins";
  33. }
  34. }
  35. };
  36. compare (userChoice,computerChoice);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement