Advertisement
Yehosua_Selah

Untitled

Aug 7th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. alert("Welcome to Rock, Paper or Scissors Game!\n\t ~Written By: Yehosua Selah~");
  2. var userName = prompt("Please enter your name");
  3. userName = userName.charAt(0).toUpperCase() + userName.slice(1);
  4. while(userName.length < 1 === true) {
  5. alert("Please don't leave it blank!");
  6. userName = prompt("Please enter your name");
  7. userName = userName.charAt(0).toUpperCase() + userName.slice(1);
  8. userName.length < 1 === false;
  9. };
  10.  
  11. alert("Let's play Rock, Paper, or Scissors" + " " + userName + "!");
  12. var userAnswer = prompt("Are you ready?").toLowerCase();
  13.  
  14. while ((userAnswer != "yes" && userAnswer != "no") == true){
  15. alert("Please answer either 'yes' or 'no' only!")
  16. userAnswer = prompt("Are you ready?").toLowerCase();
  17. ((userAnswer != "yes" && userAnswer != "no") == false)
  18. };
  19.  
  20. if(userAnswer === "yes") {
  21. alert("Okay! Let's continue!");
  22. };
  23. if (userAnswer === "no") {
  24. alert("Don't worry! I won't cheat on you!");
  25. };
  26.  
  27. var foeName = prompt(userName + ", " + "please create your enemy's name!");
  28. foeName = foeName.charAt(0).toUpperCase() + foeName.slice(1);
  29. while(foeName.length < 1 === true){
  30. alert("Please don't leave it blank!");
  31. foeName = prompt(userName + ", " + "please create your enemy's name!");
  32. foeName = foeName.charAt(0).toUpperCase() + foeName.slice(1);
  33. foeName.length < 1 === false;
  34. };
  35.  
  36. alert("The game battle is between" + " \n\t" + userName + " " + "vs." + " " + foeName);
  37. alert("Are both players ready?");
  38. alert("Let the game begin!")
  39.  
  40. var userChoice = prompt(userName + ", " + "do you choose rock, paper or scissors?").toLowerCase();
  41. while ( (userChoice != "rock" && userChoice != "paper" && userChoice != "scissors") === true ) {
  42. alert("Oh No!!! That's not a valid choice! \n\t\tChoose again!");
  43.  
  44. ((userChoice != "rock" && userChoice != "paper" && userChoice != "scissors") === false )
  45. userChoice = prompt("Do you choose rock, paper or scissors?").toLowerCase()
  46.  
  47. };
  48.  
  49. var computerChoice = Math.random();
  50. if (computerChoice < 0.34) {
  51. computerChoice = "rock";
  52. } else if(computerChoice <= 0.67) {
  53. computerChoice = "paper";
  54. } else {
  55. computerChoice = "scissors";
  56. }
  57. var compare = function (choice1,choice2) {
  58. if (choice1 === choice2) {
  59. return alert("Draw game!");
  60. }
  61.  
  62. else if (choice1 === "rock") {
  63. if (choice2 === "scissors") {
  64. return alert("Computer Chose Scissors! \n\t\tYou win!");
  65. }
  66. else
  67. {
  68. return alert("Computer Chose Paper! \n\tComputer wins!");
  69. }
  70. }
  71. else if (choice1 === "paper") {
  72. if (choice2 === "rock") {
  73. return alert("Computer Chose Rock! \n\tYou win!");
  74. }
  75. else
  76. {
  77. return alert("Computer Chose Scissors! \n\tComputer wins!");
  78. }
  79. }
  80. else if (choice1 === "scissors") {
  81. if (choice2 === "rock") {
  82. return alert("Computer Chose Rock! \n\tComputer wins!");
  83. }
  84. }
  85. else
  86. {
  87. return alert("Computer Chose Paper! \n\t\tYou win!");
  88. }
  89. };
  90.  
  91. compare (userChoice, computerChoice);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement