Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. var suits = ["Spades", "Hearts", "Clubs", "Diamonds"];
  2. var cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"];
  3.  
  4. var attempts = 1;
  5. var war = false;
  6.  
  7. var computerScore = 26;
  8. var userScore = 26;
  9.  
  10.  
  11. while (computerScore < 52 && userScore < 52)
  12. {
  13.  
  14. var computerIndex = Math.floor(Math.random() * cards.length);
  15. var userIndex = Math.floor(Math.random() * cards.length);
  16.  
  17. var computerCard = cards[computerIndex];
  18. var userCard = cards[userIndex];
  19. var computerSuit = suits[Math.floor(Math.random()*suits.length)];
  20. var userSuit = suits[Math.floor(Math.random()*suits.length)];
  21.  
  22. alert("I drew a " + computerCard + " of " + computerSuit +"nYou drew a " + userCard + " of " + userSuit);
  23.  
  24. if (computerIndex > userIndex && war == false)
  25. {
  26. computerScore++;
  27. userScore--;
  28. alert("I win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
  29. }
  30.  
  31. else if (computerIndex < userIndex && war == false)
  32. {
  33. computerScore--;
  34. userScore++;
  35. alert("You win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
  36. }
  37.  
  38. else if (computerIndex == userIndex && war == false)
  39. {
  40. alert("TIE! TIME FOR WAR! nnI have " + computerScore + " cards and you have " + userScore + " cards")
  41. war = true;
  42.  
  43. var computerIndex = Math.floor(Math.random() * cards.length);
  44. var userIndex = Math.floor(Math.random() * cards.length);
  45.  
  46. var computerCard = cards[computerIndex];
  47. var userCard = cards[userIndex];
  48. var computerSuit = suits[Math.floor(Math.random()*suits.length)];
  49. var userSuit = suits[Math.floor(Math.random()*suits.length)];
  50.  
  51. alert("I drew a " + computerCard + " of " + computerSuit +"nYou drew a " + userCard + " of " + userSuit);
  52.  
  53. if (computerIndex > userIndex && war == true)
  54. {
  55. computerScore = computerScore + (attempts * 3);
  56. userScore = userScore - (attempts * 3);
  57. alert("I win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
  58. war = false;
  59. attempts = 1;
  60. }
  61.  
  62. else if (computerIndex < userIndex && war == true)
  63. {
  64. userScore = userScore + (attempts * 3);
  65. computerScore = computerScore - (attempts * 3);
  66. alert("You win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
  67. war = false;
  68. attempts = 1;
  69. }
  70.  
  71. else
  72. {
  73. alert("TIE! TIME FOR WAR (AGAIN)! nnI have " + computerScore + " cards and you have " + userScore + " cards")
  74. attempts++;
  75.  
  76. var computerIndex = Math.floor(Math.random() * cards.length);
  77. var userIndex = Math.floor(Math.random() * cards.length);
  78.  
  79. var computerCard = cards[computerIndex];
  80. var userCard = cards[userIndex];
  81. var computerSuit = suits[Math.floor(Math.random()*suits.length)];
  82. var userSuit = suits[Math.floor(Math.random()*suits.length)];
  83.  
  84. alert("I drew a " + computerCard + " of " + computerSuit +"nYou drew a " + userCard + " of " + userSuit);
  85.  
  86. if (computerIndex == userIndex)
  87. {
  88. war = true;
  89. }
  90.  
  91. else
  92. {
  93. war = false;
  94. }
  95. }
  96. }
  97. }
  98.  
  99. if (computerScore >= 52)
  100. {
  101. alert("I WIN! GOOD GAME!");
  102. }
  103. else
  104. {
  105. alert("YOU WIN! GOOD GAME!")
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement