RPS with score, play again, shortcuts, and feedback

Public

Get raw version
javascript
  1. var scoreWin = 0;
  2. var scoreLose = 0;
  3. var scoreTie = 0;
  4. var playTheGame =function() {
  5. var userChoice = prompt("Do you choose rock (r), paper(p), or scissors(s)?").toLowerCase();
  6. while (userChoice !== "rock" && userChoice !== "paper" && userChoice !== "scissors" && userChoice !== "r" && userChoice !== "p" && userChoice !== "s") {
  7. confirm(userChoice + " is an invalid entry.");
  8. userChoice = prompt ("Please choose only rock (r), paper(p), or scissors(s).").toLowerCase();
  9. }
  10. var computerChoice = Math.random();
  11. if (computerChoice < 0.34) {
  12. computerChoice = "rock";
  13. }
  14. else if(computerChoice <= 0.67) {
  15. computerChoice = "paper";
  16. }
  17. else {
  18. computerChoice = "scissors";
  19. }
  20. console.log("The computer has picked: " + computerChoice);
  21. var compare = function (choice1, choice2) {
  22. if (choice1 === choice2) {
  23. scoreTie ++;
  24. return "The result is a tie!";
  25. }
  26. if (choice1 === "rock") {
  27. console.log("You have picked: Rock");
  28. if (choice2 === "scissors"){
  29. scoreWin ++;
  30. return "rock wins!";
  31. }
  32. else {
  33. scoreLose ++;
  34. return "paper wins!";
  35. }
  36. }
  37. if (choice1 === "paper") {
  38. console.log("You have picked: Paper");
  39. if (choice2 === "rock") {
  40. scoreWin ++;
  41. return "paper wins!";
  42. }
  43. else {
  44. scoreLose ++;
  45. return "scissors wins!";
  46. }
  47. }
  48. if (choice1 === "scissors") {
  49. console.log("You have picked: Scissors");
  50. if (choice2 === "rock") {
  51. scoreLose ++;
  52. return "rock wins!";
  53. }
  54. else {
  55. scoreWin ++;
  56. return "scissors wins!";
  57. }
  58. }
  59. if (choice1 === "r") {
  60. console.log("You have picked: Rock");
  61. if (choice2 === "scissors"){
  62. scoreWin ++;
  63. return "rock wins!";
  64. }
  65. else {
  66. scoreLose ++;
  67. return "paper wins!";
  68. }
  69. }
  70. if (choice1 === "p") {
  71. console.log("You have picked: Paper");
  72. if (choice2 === "rock") {
  73. scoreWin ++;
  74. return "paper wins!";
  75. }
  76. else {
  77. scoreLose ++;
  78. return "scissors wins!";
  79. }
  80. }
  81. if (choice1 === "s") {
  82. console.log("You have picked: Scissors");
  83. if (choice2 === "rock") {
  84. scoreLose ++;
  85. return "rock wins!";
  86. }
  87. else {
  88. scoreWin ++;
  89. return "scissors wins!";
  90. }
  91. }
  92. };
  93. theResult = compare(userChoice,computerChoice);
  94. console.log("The result is " + theResult);
  95. alert("The result is " + theResult);
  96. console.log(" ");
  97. var playAgain = prompt("Would you like to play again?").toLowerCase();
  98. while (playAgain !== "yes" && playAgain !== "no") {
  99. confirm(playAgain + " is an invalid entry.");
  100. playAgain = prompt ("Play again? Yes or no.").toLowerCase();
  101. }
  102. if (playAgain === "yes") {
  103. playTheGame();
  104. }
  105. else {
  106. confirm("You have won: " + scoreWin + '\n' +
  107. "You have lost: "+ scoreLose + '\n' +
  108. "You have tied: "+ scoreTie);
  109. console.log("You have won " + scoreWin + " times and lost " + scoreLose + " times. There was also " + scoreTie + " ties. Thanks for playing!");
  110. console.log(" ");
  111.  
  112. var feedback = prompt("How did you like that game? (1-10)");
  113. while (feedback !== "1" && feedback !== "2" && feedback !== "3" && feedback !== "4"&& feedback !== "5" && feedback !== "6" && feedback !== "7" && feedback !== "8" && feedback !== "9" && feedback !== "10") {
  114. confirm(feedback + " is an invalid entry.");
  115. feedback = prompt("How did you like that game? (1-10)");
  116. }
  117. if (feedback >= 7) {
  118. console.log("Thank you!");
  119. }
  120. else {
  121. console.log("Not my fault you don't like it!");
  122. }
  123. }
  124. };
  125. playTheGame();

RPS BBT with score, play again, and feedback

Get raw version
javascript
  1. var scoreWin = 0;
  2. var scoreLose = 0;
  3. var scoreTie = 0;
  4. var playTheGame =function() {
  5. var userChoice = prompt("Do you choose rock, paper, scissors, lizard, or Spock?").toLowerCase();
  6. while (userChoice !== "rock" && userChoice !== "paper" && userChoice !== "scissors" && userChoice !== "lizard" && userChoice !== "spock") {
  7. confirm(userChoice + " is an invalid entry.");
  8. userChoice = prompt ("Please choose rock, paper, scissors, lizard, or Spock.").toLowerCase();
  9. }
  10. var computerChoice = Math.random();
  11. if (computerChoice < 0.17) {
  12. computerChoice = "rock";
  13. }
  14. else if(computerChoice <= 0.33) {
  15. computerChoice = "paper";
  16. }
  17. else if(computerChoice <= 0.50) {
  18. computerChoice = "scissors";
  19. }
  20. else if(computerChoice <= 0.66) {
  21. computerChoice = "lizard";
  22. }
  23. else {
  24. computerChoice = "spock";
  25. }
  26. console.log("The computer has picked: " + computerChoice);
  27. console.log("You have picked: " + userChoice);
  28. var compare = function (choice1, choice2) {
  29. if (choice1 === choice2) {
  30. scoreTie ++;
  31. return "The result is a tie!";
  32. }
  33. if (choice1 === "rock") {
  34. if (choice2 === "scissors"){
  35. scoreWin ++;
  36. return "Rock smashes scissors!";
  37. }
  38. else if (choice2 === "paper") {
  39. scoreLose ++;
  40. return "Paper covers rock!";
  41. }
  42. else if (choice2 === "spock") {
  43. scoreLose ++;
  44. return "Spock vapourises rock!";
  45. }
  46. else if (choice2 === "lizard") {
  47. scoreWin ++;
  48. return "Rock crushes lizard!";
  49. }
  50. }
  51. if (choice1 === "paper") {
  52. if (choice2 === "rock") {
  53. scoreWin ++;
  54. return "Paper covers rock!";
  55. }
  56. else if (choice2 === "scissors") {
  57. scoreLose ++;
  58. return "Scissors cut paper!";
  59. }
  60. else if (choice2 === "spock") {
  61. scoreWin ++;
  62. return "Paper disproves spock";
  63. }
  64. else if (choice2 === "lizard") {
  65. scoreLose ++;
  66. return "Lizard eats paper!";
  67. }
  68. }
  69. if (choice1 === "scissors") {
  70. if (choice2 === "rock") {
  71. scoreLose ++;
  72. return "Rock smashes scissors!";
  73. }
  74. else if (choice2 === "paper") {
  75. scoreWin ++;
  76. return "Scissors cut paper!";
  77. }
  78. else if (choice2 === "spock") {
  79. scoreLose ++;
  80. return "Spock smashes scissors!";
  81. }
  82. else if (choice2 === "lizard") {
  83. scoreWin ++;
  84. return "Scissors decapitate lizard!";
  85. }
  86. }
  87. if (choice1 === "spock") {
  88. if (choice2 === "rock") {
  89. scoreWin ++;
  90. return "Spock vapourises rock!";
  91. }
  92. else if (choice2 === "paper") {
  93. scoreLose ++;
  94. return "Paper disproves Spock!";
  95. }
  96. else if (choice2 === "sscissors") {
  97. scoreWin ++;
  98. return "Spock smashes scissors!";
  99. }
  100. else if (choice2 === "lizard") {
  101. scoreLose ++;
  102. return "Lizard poisons Spock!";
  103. }
  104. }
  105. if (choice1 === "lizard") {
  106. if (choice2 === "rock") {
  107. scoreLose ++;
  108. return "Rock crushes lizard!";
  109. }
  110. else if (choice2 === "paper") {
  111. scoreWin ++;
  112. return "Lizard eats paper!";
  113. }
  114. else if (choice2 === "scissors") {
  115. scoreLose ++;
  116. return "Scissors decapitate lizard!";
  117. }
  118. else if (choice2 === "spock") {
  119. scoreWin ++;
  120. return "Lizard poisons Spock!";
  121. }
  122. }
  123.  
  124. };
  125. theResult = compare(userChoice,computerChoice);
  126. console.log("The result is " + theResult);
  127. alert("The result is " + theResult);
  128. console.log(" ");
  129. var playAgain = prompt("Would you like to play again?").toLowerCase();
  130. while (playAgain !== "yes" && playAgain !== "no") {
  131. confirm(playAgain + " is an invalid entry.");
  132. playAgain = prompt ("Play again? Yes or no.").toLowerCase();
  133. }
  134. if (playAgain === "yes") {
  135. playTheGame();
  136. }
  137. else {
  138. confirm("You have won: " + scoreWin + " Made by:" + '\n' +
  139. "You have lost: "+ scoreLose + " Codey P." + '\n' +
  140. "You have tied: "+ scoreTie);
  141. console.log("You have won " + scoreWin + " times and lost " + scoreLose + " times. There was also " + scoreTie + " ties. Thanks for playing!");
  142. console.log(" ");
  143.  
  144. var feedback = prompt("How did you like that game? (1-10)");
  145. while (feedback !== "1" && feedback !== "2" && feedback !== "3" && feedback !== "4"&& feedback !== "5" && feedback !== "6" && feedback !== "7" && feedback !== "8" && feedback !== "9" && feedback !== "10" && feedback !== "11") {
  146. confirm(feedback + " is an invalid entry.");
  147. feedback = prompt("How did you like that game? (1-10)");
  148. }
  149. if (feedback >= 11) {
  150. console.log("Well thanks for saying it is better then perfect!");
  151. alert("Well thanks for saying it is better then perfect!");
  152. }
  153. if (feedback >= 7) {
  154. console.log("Thank you!");
  155. alert("Thank you!");
  156. }
  157. else {
  158. console.log("I am sorry you don't like it. I will try to improve it!");
  159. alert("I am sorry you don't like it. I will try to improve it!");
  160. }
  161. }
  162. };
  163. playTheGame();

RPS BBT 2 players, with score, play again, and feedbackwith score,

Get raw version
javascript
  1. var player1Win = 0;
  2. var player1Lose = 0;
  3. var player2Win = 0;
  4. var player2Lose = 0;
  5. var scoreTie = 0;
  6. var playTheGame =function() {
  7. var player1 = prompt("Do you choose rock, paper, scissors, lizard, or Spock?").toLowerCase();
  8. while (player1 !== "rock" && player1 !== "paper" && player1 !== "scissors" && player1 !== "lizard" && player1 !== "spock") {
  9. confirm(player1 + " is an invalid entry.");
  10. player1 = prompt ("Please choose rock, paper, scissors, lizard, or Spock.").toLowerCase();
  11. }
  12. var player2 = prompt("Do you choose rock, paper, scissors, lizard, or Spock?").toLowerCase();
  13. while (player2 !== "rock" && player2 !== "paper" && player2 !== "scissors" && player2 !== "lizard" && player2 !== "spock") {
  14. confirm(player2 + " is an invalid entry.");
  15. player2 = prompt ("Please choose rock, paper, scissors, lizard, or Spock.").toLowerCase();
  16. }
  17. console.log("Player 1 has picked: " + player1);
  18. console.log("Player 2 has picked: " + player2);
  19. var compare = function (choice1, choice2) {
  20. if (choice1 === choice2) {
  21. scoreTie ++;
  22. return "The result is a tie!";
  23. }
  24. if (choice1 === "rock") {
  25. if (choice2 === "scissors"){
  26. scoreWin ++;
  27. return "Rock smashes scissors!";
  28. }
  29. else if (choice2 === "paper") {
  30. scoreLose ++;
  31. return "Paper covers rock!";
  32. }
  33. else if (choice2 === "spock") {
  34. scoreLose ++;
  35. return "Spock vapourises rock!";
  36. }
  37. else if (choice2 === "lizard") {
  38. scoreWin ++;
  39. return "Rock crushes lizard!";
  40. }
  41. }
  42. if (choice1 === "paper") {
  43. if (choice2 === "rock") {
  44. player1Win ++;
  45. player2Lose++;
  46. return "Paper covers rock!";
  47. }
  48. else if (choice2 === "scissors") {
  49. player1Lose ++;
  50. player2Win ++;
  51. return "Scissors cut paper!";
  52. }
  53. else if (choice2 === "spock") {
  54. player1Win ++;
  55. player2Lose ++;
  56. return "Paper disproves spock";
  57. }
  58. else if (choice2 === "lizard") {
  59. player1Lose ++;
  60. player2Win ++;
  61. return "Lizard eats paper!";
  62. }
  63. }
  64. if (choice1 === "scissors") {
  65. if (choice2 === "rock") {
  66. scoreLose ++;
  67. return "Rock smashes scissors!";
  68. }
  69. else if (choice2 === "paper") {
  70. scoreWin ++;
  71. return "Scissors cut paper!";
  72. }
  73. else if (choice2 === "spock") {
  74. scoreLose ++;
  75. return "Spock smashes scissors!";
  76. }
  77. else if (choice2 === "lizard") {
  78. scoreWin ++;
  79. return "Scissors decapitate lizard!";
  80. }
  81. }
  82. if (choice1 === "spock") {
  83. if (choice2 === "rock") {
  84. scoreWin ++;
  85. return "Spock vapourises rock!";
  86. }
  87. else if (choice2 === "paper") {
  88. scoreLose ++;
  89. return "Paper disproves Spock!";
  90. }
  91. else if (choice2 === "sscissors") {
  92. scoreWin ++;
  93. return "Spock smashes scissors!";
  94. }
  95. else if (choice2 === "lizard") {
  96. scoreLose ++;
  97. return "Lizard poisons Spock!";
  98. }
  99. }
  100. if (choice1 === "lizard") {
  101. if (choice2 === "rock") {
  102. scoreLose ++;
  103. return "Rock crushes lizard!";
  104. }
  105. else if (choice2 === "paper") {
  106. scoreWin ++;
  107. return "Lizard eats paper!";
  108. }
  109. else if (choice2 === "scissors") {
  110. scoreLose ++;
  111. return "Scissors decapitate lizard!";
  112. }
  113. else if (choice2 === "spock") {
  114. scoreWin ++;
  115. return "Lizard poisons Spock!";
  116. }
  117. }
  118.  
  119. };
  120. theResult = compare(player1,player2);
  121. console.log("The result is " + theResult);
  122. alert("The result is " + theResult);
  123. console.log(" ");
  124. var playAgain = prompt("Would you like to play again?").toLowerCase();
  125. while (playAgain !== "yes" && playAgain !== "no") {
  126. confirm(playAgain + " is an invalid entry.");
  127. playAgain = prompt ("Play again? Yes or no.").toLowerCase();
  128. }
  129. if (playAgain === "yes") {
  130. playTheGame();
  131. }
  132. else {
  133. confirm("Player1: Wins:" + player1Win + " Loses:" + player1Lose + '\n' +
  134. "Player2: Wins:" + player1Win + " Loses:" + player1Lose + '\n' +
  135. "Tie games: "+ scoreTie);
  136. console.log(" ");
  137.  
  138. var feedback = prompt("How did you like that game? (1-10)");
  139. while (feedback !== "1" && feedback !== "2" && feedback !== "3" && feedback !== "4"&& feedback !== "5" && feedback !== "6" && feedback !== "7" && feedback !== "8" && feedback !== "9" && feedback !== "10" && feedback !== "11") {
  140. confirm(feedback + " is an invalid entry.");
  141. feedback = prompt("How did you like that game? (1-10)");
  142. }
  143. if (feedback >= 11) {
  144. console.log("Well thanks for saying it is better then perfect!");
  145. alert("Well thanks for saying it is better then perfect!");
  146. }
  147. if (feedback >= 7) {
  148. console.log("Thank you!");
  149. alert("Thank you!");
  150. }
  151. else {
  152. console.log("I am sorry you don't like it. I will try to improve it!");
  153. alert("I am sorry you don't like it. I will try to improve it!");
  154. }
  155. }
  156. };
  157. playTheGame();