Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var suits = ["Spades", "Hearts", "Clubs", "Diamonds"];
- var cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"];
- var attempts = 1;
- var war = false;
- var computerScore = 26;
- var userScore = 26;
- while (computerScore < 52 && userScore < 52)
- {
- var computerIndex = Math.floor(Math.random() * cards.length);
- var userIndex = Math.floor(Math.random() * cards.length);
- var computerCard = cards[computerIndex];
- var userCard = cards[userIndex];
- var computerSuit = suits[Math.floor(Math.random()*suits.length)];
- var userSuit = suits[Math.floor(Math.random()*suits.length)];
- alert("I drew a " + computerCard + " of " + computerSuit +"nYou drew a " + userCard + " of " + userSuit);
- if (computerIndex > userIndex && war == false)
- {
- computerScore++;
- userScore--;
- alert("I win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
- }
- else if (computerIndex < userIndex && war == false)
- {
- computerScore--;
- userScore++;
- alert("You win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
- }
- else if (computerIndex == userIndex && war == false)
- {
- alert("TIE! TIME FOR WAR! nnI have " + computerScore + " cards and you have " + userScore + " cards")
- war = true;
- var computerIndex = Math.floor(Math.random() * cards.length);
- var userIndex = Math.floor(Math.random() * cards.length);
- var computerCard = cards[computerIndex];
- var userCard = cards[userIndex];
- var computerSuit = suits[Math.floor(Math.random()*suits.length)];
- var userSuit = suits[Math.floor(Math.random()*suits.length)];
- alert("I drew a " + computerCard + " of " + computerSuit +"nYou drew a " + userCard + " of " + userSuit);
- if (computerIndex > userIndex && war == true)
- {
- computerScore = computerScore + (attempts * 3);
- userScore = userScore - (attempts * 3);
- alert("I win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
- war = false;
- attempts = 1;
- }
- else if (computerIndex < userIndex && war == true)
- {
- userScore = userScore + (attempts * 3);
- computerScore = computerScore - (attempts * 3);
- alert("You win. nnI have " + computerScore + " cards and you have " + userScore + " cards.");
- war = false;
- attempts = 1;
- }
- else
- {
- alert("TIE! TIME FOR WAR (AGAIN)! nnI have " + computerScore + " cards and you have " + userScore + " cards")
- attempts++;
- var computerIndex = Math.floor(Math.random() * cards.length);
- var userIndex = Math.floor(Math.random() * cards.length);
- var computerCard = cards[computerIndex];
- var userCard = cards[userIndex];
- var computerSuit = suits[Math.floor(Math.random()*suits.length)];
- var userSuit = suits[Math.floor(Math.random()*suits.length)];
- alert("I drew a " + computerCard + " of " + computerSuit +"nYou drew a " + userCard + " of " + userSuit);
- if (computerIndex == userIndex)
- {
- war = true;
- }
- else
- {
- war = false;
- }
- }
- }
- }
- if (computerScore >= 52)
- {
- alert("I WIN! GOOD GAME!");
- }
- else
- {
- alert("YOU WIN! GOOD GAME!")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement