diff --git a/README.md b/README.md index b895afbe..c6953d17 100644 --- a/README.md +++ b/README.md @@ -1 +1,23 @@ # Rocket Academy Coding Basics: Blackjack + +## Overview +This project is a simple implementation of a card game inspired by Blackjack, built as part of Rocket Academy's Coding Fundamentals course. The game allows the player to compete against the computer by drawing cards, with the goal of reaching as close to 21 points as possible without exceeding it. + +## How to Play +1. Click the "Play" button to start the game. Both the player and the computer will receive two cards each. +2. The scores are calculated based on the values of the cards. If either player has a score of 21 (Blackjack), the game ends immediately, and the winner is declared. +3. If neither player has a Blackjack, the player can choose to either: + - **Hit**: Draw another card to increase their score. + - **Stand**: End their turn and let the computer play. +4. The computer will continue drawing cards until its score is 17 or more. +5. The player and computer scores are compared, and the winner is determined based on who is closer to 21 without exceeding it. +6. The player can restart the game at any time by clicking the "Restart" button. + +## Instructions +1. Clone the repository. +2. Open the index.html file in a browser. +3. Start playing by clicking the "Play" button. + +## Game Screenshot + + diff --git a/images/__MACOSX/images/._aceOfClubs.jpg b/images/__MACOSX/images/._aceOfClubs.jpg new file mode 100644 index 00000000..f33fdc4e Binary files /dev/null and b/images/__MACOSX/images/._aceOfClubs.jpg differ diff --git a/images/__MACOSX/images/._aceOfDiamonds.jpg b/images/__MACOSX/images/._aceOfDiamonds.jpg new file mode 100644 index 00000000..e20c7b0e Binary files /dev/null and b/images/__MACOSX/images/._aceOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._aceOfHearts.jpg b/images/__MACOSX/images/._aceOfHearts.jpg new file mode 100644 index 00000000..ca59ace0 Binary files /dev/null and b/images/__MACOSX/images/._aceOfHearts.jpg differ diff --git a/images/__MACOSX/images/._aceOfSpades.jpg b/images/__MACOSX/images/._aceOfSpades.jpg new file mode 100644 index 00000000..d5ac6b17 Binary files /dev/null and b/images/__MACOSX/images/._aceOfSpades.jpg differ diff --git a/images/__MACOSX/images/._chip.png b/images/__MACOSX/images/._chip.png new file mode 100644 index 00000000..7347d20f Binary files /dev/null and b/images/__MACOSX/images/._chip.png differ diff --git a/images/__MACOSX/images/._eightOfClubs.jpg b/images/__MACOSX/images/._eightOfClubs.jpg new file mode 100644 index 00000000..11018791 Binary files /dev/null and b/images/__MACOSX/images/._eightOfClubs.jpg differ diff --git a/images/__MACOSX/images/._eightOfDiamonds.jpg b/images/__MACOSX/images/._eightOfDiamonds.jpg new file mode 100644 index 00000000..92fce9e9 Binary files /dev/null and b/images/__MACOSX/images/._eightOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._eightOfHearts.jpg b/images/__MACOSX/images/._eightOfHearts.jpg new file mode 100644 index 00000000..640af8f1 Binary files /dev/null and b/images/__MACOSX/images/._eightOfHearts.jpg differ diff --git a/images/__MACOSX/images/._eightOfSpades.jpg b/images/__MACOSX/images/._eightOfSpades.jpg new file mode 100644 index 00000000..8d6a4e87 Binary files /dev/null and b/images/__MACOSX/images/._eightOfSpades.jpg differ diff --git a/images/__MACOSX/images/._fiveOfClubs.jpg b/images/__MACOSX/images/._fiveOfClubs.jpg new file mode 100644 index 00000000..d0342721 Binary files /dev/null and b/images/__MACOSX/images/._fiveOfClubs.jpg differ diff --git a/images/__MACOSX/images/._fiveOfDiamonds.jpg b/images/__MACOSX/images/._fiveOfDiamonds.jpg new file mode 100644 index 00000000..d86f61bb Binary files /dev/null and b/images/__MACOSX/images/._fiveOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._fiveOfHearts.jpg b/images/__MACOSX/images/._fiveOfHearts.jpg new file mode 100644 index 00000000..3a77ce9a Binary files /dev/null and b/images/__MACOSX/images/._fiveOfHearts.jpg differ diff --git a/images/__MACOSX/images/._fiveOfSpades.jpg b/images/__MACOSX/images/._fiveOfSpades.jpg new file mode 100644 index 00000000..b0832575 Binary files /dev/null and b/images/__MACOSX/images/._fiveOfSpades.jpg differ diff --git a/images/__MACOSX/images/._fourOfClubs.jpg b/images/__MACOSX/images/._fourOfClubs.jpg new file mode 100644 index 00000000..0d418d72 Binary files /dev/null and b/images/__MACOSX/images/._fourOfClubs.jpg differ diff --git a/images/__MACOSX/images/._fourOfDiamonds.jpg b/images/__MACOSX/images/._fourOfDiamonds.jpg new file mode 100644 index 00000000..bbfedcd3 Binary files /dev/null and b/images/__MACOSX/images/._fourOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._fourOfHearts.jpg b/images/__MACOSX/images/._fourOfHearts.jpg new file mode 100644 index 00000000..9e2158da Binary files /dev/null and b/images/__MACOSX/images/._fourOfHearts.jpg differ diff --git a/images/__MACOSX/images/._fourOfSpades.jpg b/images/__MACOSX/images/._fourOfSpades.jpg new file mode 100644 index 00000000..bcf6ad12 Binary files /dev/null and b/images/__MACOSX/images/._fourOfSpades.jpg differ diff --git a/images/__MACOSX/images/._jackOfClubs.jpg b/images/__MACOSX/images/._jackOfClubs.jpg new file mode 100644 index 00000000..12b8b2c1 Binary files /dev/null and b/images/__MACOSX/images/._jackOfClubs.jpg differ diff --git a/images/__MACOSX/images/._jackOfDiamonds.jpg b/images/__MACOSX/images/._jackOfDiamonds.jpg new file mode 100644 index 00000000..0a66ec56 Binary files /dev/null and b/images/__MACOSX/images/._jackOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._jackOfHearts.jpg b/images/__MACOSX/images/._jackOfHearts.jpg new file mode 100644 index 00000000..eecd6c82 Binary files /dev/null and b/images/__MACOSX/images/._jackOfHearts.jpg differ diff --git a/images/__MACOSX/images/._jackOfSpades.jpg b/images/__MACOSX/images/._jackOfSpades.jpg new file mode 100644 index 00000000..c4435fbd Binary files /dev/null and b/images/__MACOSX/images/._jackOfSpades.jpg differ diff --git a/images/__MACOSX/images/._kingOfDiamonds.jpg b/images/__MACOSX/images/._kingOfDiamonds.jpg new file mode 100644 index 00000000..7c94fca0 Binary files /dev/null and b/images/__MACOSX/images/._kingOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._kingOfHearts.jpg b/images/__MACOSX/images/._kingOfHearts.jpg new file mode 100644 index 00000000..f06a01e3 Binary files /dev/null and b/images/__MACOSX/images/._kingOfHearts.jpg differ diff --git a/images/__MACOSX/images/._kingOfSpades.jpg b/images/__MACOSX/images/._kingOfSpades.jpg new file mode 100644 index 00000000..788cbd92 Binary files /dev/null and b/images/__MACOSX/images/._kingOfSpades.jpg differ diff --git a/images/__MACOSX/images/._kingofClubs.jpg b/images/__MACOSX/images/._kingofClubs.jpg new file mode 100644 index 00000000..76536b57 Binary files /dev/null and b/images/__MACOSX/images/._kingofClubs.jpg differ diff --git a/images/__MACOSX/images/._nineOfClubs.jpg b/images/__MACOSX/images/._nineOfClubs.jpg new file mode 100644 index 00000000..fa45dfa8 Binary files /dev/null and b/images/__MACOSX/images/._nineOfClubs.jpg differ diff --git a/images/__MACOSX/images/._nineOfDiamonds.jpg b/images/__MACOSX/images/._nineOfDiamonds.jpg new file mode 100644 index 00000000..16f79dcc Binary files /dev/null and b/images/__MACOSX/images/._nineOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._nineOfHearts.jpg b/images/__MACOSX/images/._nineOfHearts.jpg new file mode 100644 index 00000000..53fcdaae Binary files /dev/null and b/images/__MACOSX/images/._nineOfHearts.jpg differ diff --git a/images/__MACOSX/images/._nineOfSpades.jpg b/images/__MACOSX/images/._nineOfSpades.jpg new file mode 100644 index 00000000..fec70971 Binary files /dev/null and b/images/__MACOSX/images/._nineOfSpades.jpg differ diff --git a/images/__MACOSX/images/._queenOfClubs.jpg b/images/__MACOSX/images/._queenOfClubs.jpg new file mode 100644 index 00000000..1d0ab58e Binary files /dev/null and b/images/__MACOSX/images/._queenOfClubs.jpg differ diff --git a/images/__MACOSX/images/._queenOfDiamonds.jpg b/images/__MACOSX/images/._queenOfDiamonds.jpg new file mode 100644 index 00000000..e1ceb001 Binary files /dev/null and b/images/__MACOSX/images/._queenOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._queenOfHearts.jpg b/images/__MACOSX/images/._queenOfHearts.jpg new file mode 100644 index 00000000..bfcbdc2c Binary files /dev/null and b/images/__MACOSX/images/._queenOfHearts.jpg differ diff --git a/images/__MACOSX/images/._queenOfSpades.jpg b/images/__MACOSX/images/._queenOfSpades.jpg new file mode 100644 index 00000000..76aa0995 Binary files /dev/null and b/images/__MACOSX/images/._queenOfSpades.jpg differ diff --git a/images/__MACOSX/images/._sevenOfClubs.jpg b/images/__MACOSX/images/._sevenOfClubs.jpg new file mode 100644 index 00000000..1e70bacf Binary files /dev/null and b/images/__MACOSX/images/._sevenOfClubs.jpg differ diff --git a/images/__MACOSX/images/._sevenOfDiamonds.jpg b/images/__MACOSX/images/._sevenOfDiamonds.jpg new file mode 100644 index 00000000..03032b22 Binary files /dev/null and b/images/__MACOSX/images/._sevenOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._sevenOfHearts.jpg b/images/__MACOSX/images/._sevenOfHearts.jpg new file mode 100644 index 00000000..6dd46dee Binary files /dev/null and b/images/__MACOSX/images/._sevenOfHearts.jpg differ diff --git a/images/__MACOSX/images/._sevenOfSpades.jpg b/images/__MACOSX/images/._sevenOfSpades.jpg new file mode 100644 index 00000000..7428bb91 Binary files /dev/null and b/images/__MACOSX/images/._sevenOfSpades.jpg differ diff --git a/images/__MACOSX/images/._sixOfClubs.jpg b/images/__MACOSX/images/._sixOfClubs.jpg new file mode 100644 index 00000000..878f6fb2 Binary files /dev/null and b/images/__MACOSX/images/._sixOfClubs.jpg differ diff --git a/images/__MACOSX/images/._sixOfDiamonds.jpg b/images/__MACOSX/images/._sixOfDiamonds.jpg new file mode 100644 index 00000000..b5f25c2a Binary files /dev/null and b/images/__MACOSX/images/._sixOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._sixOfHearts.jpg b/images/__MACOSX/images/._sixOfHearts.jpg new file mode 100644 index 00000000..fe459edf Binary files /dev/null and b/images/__MACOSX/images/._sixOfHearts.jpg differ diff --git a/images/__MACOSX/images/._sixOfSpades.jpg b/images/__MACOSX/images/._sixOfSpades.jpg new file mode 100644 index 00000000..27cd85c2 Binary files /dev/null and b/images/__MACOSX/images/._sixOfSpades.jpg differ diff --git a/images/__MACOSX/images/._tenOfClubs.jpg b/images/__MACOSX/images/._tenOfClubs.jpg new file mode 100644 index 00000000..371449b8 Binary files /dev/null and b/images/__MACOSX/images/._tenOfClubs.jpg differ diff --git a/images/__MACOSX/images/._tenOfDiamonds.jpg b/images/__MACOSX/images/._tenOfDiamonds.jpg new file mode 100644 index 00000000..93f54375 Binary files /dev/null and b/images/__MACOSX/images/._tenOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._tenOfHearts.jpg b/images/__MACOSX/images/._tenOfHearts.jpg new file mode 100644 index 00000000..2b5d158e Binary files /dev/null and b/images/__MACOSX/images/._tenOfHearts.jpg differ diff --git a/images/__MACOSX/images/._tenOfSpades.jpg b/images/__MACOSX/images/._tenOfSpades.jpg new file mode 100644 index 00000000..a5e26f1c Binary files /dev/null and b/images/__MACOSX/images/._tenOfSpades.jpg differ diff --git a/images/__MACOSX/images/._threeOfClubs.jpg b/images/__MACOSX/images/._threeOfClubs.jpg new file mode 100644 index 00000000..5f8b8d5a Binary files /dev/null and b/images/__MACOSX/images/._threeOfClubs.jpg differ diff --git a/images/__MACOSX/images/._threeOfDiamonds.jpg b/images/__MACOSX/images/._threeOfDiamonds.jpg new file mode 100644 index 00000000..1f6e925e Binary files /dev/null and b/images/__MACOSX/images/._threeOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._threeOfHearts.jpg b/images/__MACOSX/images/._threeOfHearts.jpg new file mode 100644 index 00000000..1b3040e5 Binary files /dev/null and b/images/__MACOSX/images/._threeOfHearts.jpg differ diff --git a/images/__MACOSX/images/._threeOfSpades.jpg b/images/__MACOSX/images/._threeOfSpades.jpg new file mode 100644 index 00000000..f7bb98dc Binary files /dev/null and b/images/__MACOSX/images/._threeOfSpades.jpg differ diff --git a/images/__MACOSX/images/._twoOfClubs.jpg b/images/__MACOSX/images/._twoOfClubs.jpg new file mode 100644 index 00000000..0f8b0a74 Binary files /dev/null and b/images/__MACOSX/images/._twoOfClubs.jpg differ diff --git a/images/__MACOSX/images/._twoOfDiamonds.jpg b/images/__MACOSX/images/._twoOfDiamonds.jpg new file mode 100644 index 00000000..03dba582 Binary files /dev/null and b/images/__MACOSX/images/._twoOfDiamonds.jpg differ diff --git a/images/__MACOSX/images/._twoOfHearts.jpg b/images/__MACOSX/images/._twoOfHearts.jpg new file mode 100644 index 00000000..d16b8b2c Binary files /dev/null and b/images/__MACOSX/images/._twoOfHearts.jpg differ diff --git a/images/__MACOSX/images/._twoOfSpades.jpg b/images/__MACOSX/images/._twoOfSpades.jpg new file mode 100644 index 00000000..ce866de4 Binary files /dev/null and b/images/__MACOSX/images/._twoOfSpades.jpg differ diff --git a/images/aceOfClubs.jpg b/images/aceOfClubs.jpg new file mode 100644 index 00000000..f6424265 Binary files /dev/null and b/images/aceOfClubs.jpg differ diff --git a/images/aceOfDiamonds.jpg b/images/aceOfDiamonds.jpg new file mode 100644 index 00000000..c2545604 Binary files /dev/null and b/images/aceOfDiamonds.jpg differ diff --git a/images/aceOfHearts.jpg b/images/aceOfHearts.jpg new file mode 100644 index 00000000..91c4ebcc Binary files /dev/null and b/images/aceOfHearts.jpg differ diff --git a/images/aceOfSpades.jpg b/images/aceOfSpades.jpg new file mode 100644 index 00000000..2f9b5ac9 Binary files /dev/null and b/images/aceOfSpades.jpg differ diff --git a/images/chip.png b/images/chip.png new file mode 100644 index 00000000..dc135b5c Binary files /dev/null and b/images/chip.png differ diff --git a/images/eightOfClubs.jpg b/images/eightOfClubs.jpg new file mode 100644 index 00000000..71c953a0 Binary files /dev/null and b/images/eightOfClubs.jpg differ diff --git a/images/eightOfDiamonds.jpg b/images/eightOfDiamonds.jpg new file mode 100644 index 00000000..ac8ad77b Binary files /dev/null and b/images/eightOfDiamonds.jpg differ diff --git a/images/eightOfHearts.jpg b/images/eightOfHearts.jpg new file mode 100644 index 00000000..8bad99ad Binary files /dev/null and b/images/eightOfHearts.jpg differ diff --git a/images/eightOfSpades.jpg b/images/eightOfSpades.jpg new file mode 100644 index 00000000..e5447d0a Binary files /dev/null and b/images/eightOfSpades.jpg differ diff --git a/images/fiveOfClubs.jpg b/images/fiveOfClubs.jpg new file mode 100644 index 00000000..df98fcdc Binary files /dev/null and b/images/fiveOfClubs.jpg differ diff --git a/images/fiveOfDiamonds.jpg b/images/fiveOfDiamonds.jpg new file mode 100644 index 00000000..e9a78ff7 Binary files /dev/null and b/images/fiveOfDiamonds.jpg differ diff --git a/images/fiveOfHearts.jpg b/images/fiveOfHearts.jpg new file mode 100644 index 00000000..7559489e Binary files /dev/null and b/images/fiveOfHearts.jpg differ diff --git a/images/fiveOfSpades.jpg b/images/fiveOfSpades.jpg new file mode 100644 index 00000000..f3b42f7e Binary files /dev/null and b/images/fiveOfSpades.jpg differ diff --git a/images/fourOfClubs.jpg b/images/fourOfClubs.jpg new file mode 100644 index 00000000..fe4d9769 Binary files /dev/null and b/images/fourOfClubs.jpg differ diff --git a/images/fourOfDiamonds.jpg b/images/fourOfDiamonds.jpg new file mode 100644 index 00000000..05390f79 Binary files /dev/null and b/images/fourOfDiamonds.jpg differ diff --git a/images/fourOfHearts.jpg b/images/fourOfHearts.jpg new file mode 100644 index 00000000..a2a9f843 Binary files /dev/null and b/images/fourOfHearts.jpg differ diff --git a/images/fourOfSpades.jpg b/images/fourOfSpades.jpg new file mode 100644 index 00000000..a14c23a0 Binary files /dev/null and b/images/fourOfSpades.jpg differ diff --git a/images/images/aceOfClubs.jpg b/images/images/aceOfClubs.jpg new file mode 100644 index 00000000..f6424265 Binary files /dev/null and b/images/images/aceOfClubs.jpg differ diff --git a/images/images/aceOfDiamonds.jpg b/images/images/aceOfDiamonds.jpg new file mode 100644 index 00000000..c2545604 Binary files /dev/null and b/images/images/aceOfDiamonds.jpg differ diff --git a/images/images/aceOfHearts.jpg b/images/images/aceOfHearts.jpg new file mode 100644 index 00000000..91c4ebcc Binary files /dev/null and b/images/images/aceOfHearts.jpg differ diff --git a/images/images/aceOfSpades.jpg b/images/images/aceOfSpades.jpg new file mode 100644 index 00000000..2f9b5ac9 Binary files /dev/null and b/images/images/aceOfSpades.jpg differ diff --git a/images/images/chip.png b/images/images/chip.png new file mode 100644 index 00000000..dc135b5c Binary files /dev/null and b/images/images/chip.png differ diff --git a/images/images/eightOfClubs.jpg b/images/images/eightOfClubs.jpg new file mode 100644 index 00000000..71c953a0 Binary files /dev/null and b/images/images/eightOfClubs.jpg differ diff --git a/images/images/eightOfDiamonds.jpg b/images/images/eightOfDiamonds.jpg new file mode 100644 index 00000000..ac8ad77b Binary files /dev/null and b/images/images/eightOfDiamonds.jpg differ diff --git a/images/images/eightOfHearts.jpg b/images/images/eightOfHearts.jpg new file mode 100644 index 00000000..8bad99ad Binary files /dev/null and b/images/images/eightOfHearts.jpg differ diff --git a/images/images/eightOfSpades.jpg b/images/images/eightOfSpades.jpg new file mode 100644 index 00000000..e5447d0a Binary files /dev/null and b/images/images/eightOfSpades.jpg differ diff --git a/images/images/fiveOfClubs.jpg b/images/images/fiveOfClubs.jpg new file mode 100644 index 00000000..df98fcdc Binary files /dev/null and b/images/images/fiveOfClubs.jpg differ diff --git a/images/images/fiveOfDiamonds.jpg b/images/images/fiveOfDiamonds.jpg new file mode 100644 index 00000000..e9a78ff7 Binary files /dev/null and b/images/images/fiveOfDiamonds.jpg differ diff --git a/images/images/fiveOfHearts.jpg b/images/images/fiveOfHearts.jpg new file mode 100644 index 00000000..7559489e Binary files /dev/null and b/images/images/fiveOfHearts.jpg differ diff --git a/images/images/fiveOfSpades.jpg b/images/images/fiveOfSpades.jpg new file mode 100644 index 00000000..f3b42f7e Binary files /dev/null and b/images/images/fiveOfSpades.jpg differ diff --git a/images/images/fourOfClubs.jpg b/images/images/fourOfClubs.jpg new file mode 100644 index 00000000..fe4d9769 Binary files /dev/null and b/images/images/fourOfClubs.jpg differ diff --git a/images/images/fourOfDiamonds.jpg b/images/images/fourOfDiamonds.jpg new file mode 100644 index 00000000..05390f79 Binary files /dev/null and b/images/images/fourOfDiamonds.jpg differ diff --git a/images/images/fourOfHearts.jpg b/images/images/fourOfHearts.jpg new file mode 100644 index 00000000..a2a9f843 Binary files /dev/null and b/images/images/fourOfHearts.jpg differ diff --git a/images/images/fourOfSpades.jpg b/images/images/fourOfSpades.jpg new file mode 100644 index 00000000..a14c23a0 Binary files /dev/null and b/images/images/fourOfSpades.jpg differ diff --git a/images/images/jackOfClubs.jpg b/images/images/jackOfClubs.jpg new file mode 100644 index 00000000..246217eb Binary files /dev/null and b/images/images/jackOfClubs.jpg differ diff --git a/images/images/jackOfDiamonds.jpg b/images/images/jackOfDiamonds.jpg new file mode 100644 index 00000000..2b2d45d1 Binary files /dev/null and b/images/images/jackOfDiamonds.jpg differ diff --git a/images/images/jackOfHearts.jpg b/images/images/jackOfHearts.jpg new file mode 100644 index 00000000..f9cd2626 Binary files /dev/null and b/images/images/jackOfHearts.jpg differ diff --git a/images/images/jackOfSpades.jpg b/images/images/jackOfSpades.jpg new file mode 100644 index 00000000..ef3ed1d3 Binary files /dev/null and b/images/images/jackOfSpades.jpg differ diff --git a/images/images/kingOfDiamonds.jpg b/images/images/kingOfDiamonds.jpg new file mode 100644 index 00000000..1bdff5b0 Binary files /dev/null and b/images/images/kingOfDiamonds.jpg differ diff --git a/images/images/kingOfHearts.jpg b/images/images/kingOfHearts.jpg new file mode 100644 index 00000000..92c956c4 Binary files /dev/null and b/images/images/kingOfHearts.jpg differ diff --git a/images/images/kingOfSpades.jpg b/images/images/kingOfSpades.jpg new file mode 100644 index 00000000..f842b723 Binary files /dev/null and b/images/images/kingOfSpades.jpg differ diff --git a/images/images/kingofClubs.jpg b/images/images/kingofClubs.jpg new file mode 100644 index 00000000..e93135dd Binary files /dev/null and b/images/images/kingofClubs.jpg differ diff --git a/images/images/nineOfClubs.jpg b/images/images/nineOfClubs.jpg new file mode 100644 index 00000000..a9774cc6 Binary files /dev/null and b/images/images/nineOfClubs.jpg differ diff --git a/images/images/nineOfDiamonds.jpg b/images/images/nineOfDiamonds.jpg new file mode 100644 index 00000000..8695dcf8 Binary files /dev/null and b/images/images/nineOfDiamonds.jpg differ diff --git a/images/images/nineOfHearts.jpg b/images/images/nineOfHearts.jpg new file mode 100644 index 00000000..4a9efece Binary files /dev/null and b/images/images/nineOfHearts.jpg differ diff --git a/images/images/nineOfSpades.jpg b/images/images/nineOfSpades.jpg new file mode 100644 index 00000000..f37b860d Binary files /dev/null and b/images/images/nineOfSpades.jpg differ diff --git a/images/images/queenOfClubs.jpg b/images/images/queenOfClubs.jpg new file mode 100644 index 00000000..623bd1be Binary files /dev/null and b/images/images/queenOfClubs.jpg differ diff --git a/images/images/queenOfDiamonds.jpg b/images/images/queenOfDiamonds.jpg new file mode 100644 index 00000000..cbea4738 Binary files /dev/null and b/images/images/queenOfDiamonds.jpg differ diff --git a/images/images/queenOfHearts.jpg b/images/images/queenOfHearts.jpg new file mode 100644 index 00000000..859e9d3c Binary files /dev/null and b/images/images/queenOfHearts.jpg differ diff --git a/images/images/queenOfSpades.jpg b/images/images/queenOfSpades.jpg new file mode 100644 index 00000000..e156c0f1 Binary files /dev/null and b/images/images/queenOfSpades.jpg differ diff --git a/images/images/sevenOfClubs.jpg b/images/images/sevenOfClubs.jpg new file mode 100644 index 00000000..df3fcff9 Binary files /dev/null and b/images/images/sevenOfClubs.jpg differ diff --git a/images/images/sevenOfDiamonds.jpg b/images/images/sevenOfDiamonds.jpg new file mode 100644 index 00000000..43afee5c Binary files /dev/null and b/images/images/sevenOfDiamonds.jpg differ diff --git a/images/images/sevenOfHearts.jpg b/images/images/sevenOfHearts.jpg new file mode 100644 index 00000000..4e9445e2 Binary files /dev/null and b/images/images/sevenOfHearts.jpg differ diff --git a/images/images/sevenOfSpades.jpg b/images/images/sevenOfSpades.jpg new file mode 100644 index 00000000..4a9728cc Binary files /dev/null and b/images/images/sevenOfSpades.jpg differ diff --git a/images/images/sixOfClubs.jpg b/images/images/sixOfClubs.jpg new file mode 100644 index 00000000..00835c22 Binary files /dev/null and b/images/images/sixOfClubs.jpg differ diff --git a/images/images/sixOfDiamonds.jpg b/images/images/sixOfDiamonds.jpg new file mode 100644 index 00000000..2ec74d3f Binary files /dev/null and b/images/images/sixOfDiamonds.jpg differ diff --git a/images/images/sixOfHearts.jpg b/images/images/sixOfHearts.jpg new file mode 100644 index 00000000..27caf392 Binary files /dev/null and b/images/images/sixOfHearts.jpg differ diff --git a/images/images/sixOfSpades.jpg b/images/images/sixOfSpades.jpg new file mode 100644 index 00000000..cba6e069 Binary files /dev/null and b/images/images/sixOfSpades.jpg differ diff --git a/images/images/tenOfClubs.jpg b/images/images/tenOfClubs.jpg new file mode 100644 index 00000000..78eefd8b Binary files /dev/null and b/images/images/tenOfClubs.jpg differ diff --git a/images/images/tenOfDiamonds.jpg b/images/images/tenOfDiamonds.jpg new file mode 100644 index 00000000..7c8d0ea9 Binary files /dev/null and b/images/images/tenOfDiamonds.jpg differ diff --git a/images/images/tenOfHearts.jpg b/images/images/tenOfHearts.jpg new file mode 100644 index 00000000..3350d602 Binary files /dev/null and b/images/images/tenOfHearts.jpg differ diff --git a/images/images/tenOfSpades.jpg b/images/images/tenOfSpades.jpg new file mode 100644 index 00000000..38dcfc6f Binary files /dev/null and b/images/images/tenOfSpades.jpg differ diff --git a/images/images/threeOfClubs.jpg b/images/images/threeOfClubs.jpg new file mode 100644 index 00000000..7fc9f2ea Binary files /dev/null and b/images/images/threeOfClubs.jpg differ diff --git a/images/images/threeOfDiamonds.jpg b/images/images/threeOfDiamonds.jpg new file mode 100644 index 00000000..f6c5f238 Binary files /dev/null and b/images/images/threeOfDiamonds.jpg differ diff --git a/images/images/threeOfHearts.jpg b/images/images/threeOfHearts.jpg new file mode 100644 index 00000000..c06feb6f Binary files /dev/null and b/images/images/threeOfHearts.jpg differ diff --git a/images/images/threeOfSpades.jpg b/images/images/threeOfSpades.jpg new file mode 100644 index 00000000..8b67a6d1 Binary files /dev/null and b/images/images/threeOfSpades.jpg differ diff --git a/images/images/twoOfClubs.jpg b/images/images/twoOfClubs.jpg new file mode 100644 index 00000000..40d9c58b Binary files /dev/null and b/images/images/twoOfClubs.jpg differ diff --git a/images/images/twoOfDiamonds.jpg b/images/images/twoOfDiamonds.jpg new file mode 100644 index 00000000..6e228385 Binary files /dev/null and b/images/images/twoOfDiamonds.jpg differ diff --git a/images/images/twoOfHearts.jpg b/images/images/twoOfHearts.jpg new file mode 100644 index 00000000..b0fe2159 Binary files /dev/null and b/images/images/twoOfHearts.jpg differ diff --git a/images/images/twoOfSpades.jpg b/images/images/twoOfSpades.jpg new file mode 100644 index 00000000..65cb6ad1 Binary files /dev/null and b/images/images/twoOfSpades.jpg differ diff --git a/images/jackOfClubs.jpg b/images/jackOfClubs.jpg new file mode 100644 index 00000000..246217eb Binary files /dev/null and b/images/jackOfClubs.jpg differ diff --git a/images/jackOfDiamonds.jpg b/images/jackOfDiamonds.jpg new file mode 100644 index 00000000..2b2d45d1 Binary files /dev/null and b/images/jackOfDiamonds.jpg differ diff --git a/images/jackOfHearts.jpg b/images/jackOfHearts.jpg new file mode 100644 index 00000000..f9cd2626 Binary files /dev/null and b/images/jackOfHearts.jpg differ diff --git a/images/jackOfSpades.jpg b/images/jackOfSpades.jpg new file mode 100644 index 00000000..ef3ed1d3 Binary files /dev/null and b/images/jackOfSpades.jpg differ diff --git a/images/kingOfDiamonds.jpg b/images/kingOfDiamonds.jpg new file mode 100644 index 00000000..1bdff5b0 Binary files /dev/null and b/images/kingOfDiamonds.jpg differ diff --git a/images/kingOfHearts.jpg b/images/kingOfHearts.jpg new file mode 100644 index 00000000..92c956c4 Binary files /dev/null and b/images/kingOfHearts.jpg differ diff --git a/images/kingOfSpades.jpg b/images/kingOfSpades.jpg new file mode 100644 index 00000000..f842b723 Binary files /dev/null and b/images/kingOfSpades.jpg differ diff --git a/images/kingofClubs.jpg b/images/kingofClubs.jpg new file mode 100644 index 00000000..e93135dd Binary files /dev/null and b/images/kingofClubs.jpg differ diff --git a/images/nineOfClubs.jpg b/images/nineOfClubs.jpg new file mode 100644 index 00000000..a9774cc6 Binary files /dev/null and b/images/nineOfClubs.jpg differ diff --git a/images/nineOfDiamonds.jpg b/images/nineOfDiamonds.jpg new file mode 100644 index 00000000..8695dcf8 Binary files /dev/null and b/images/nineOfDiamonds.jpg differ diff --git a/images/nineOfHearts.jpg b/images/nineOfHearts.jpg new file mode 100644 index 00000000..4a9efece Binary files /dev/null and b/images/nineOfHearts.jpg differ diff --git a/images/nineOfSpades.jpg b/images/nineOfSpades.jpg new file mode 100644 index 00000000..f37b860d Binary files /dev/null and b/images/nineOfSpades.jpg differ diff --git a/images/queenOfClubs.jpg b/images/queenOfClubs.jpg new file mode 100644 index 00000000..623bd1be Binary files /dev/null and b/images/queenOfClubs.jpg differ diff --git a/images/queenOfDiamonds.jpg b/images/queenOfDiamonds.jpg new file mode 100644 index 00000000..cbea4738 Binary files /dev/null and b/images/queenOfDiamonds.jpg differ diff --git a/images/queenOfHearts.jpg b/images/queenOfHearts.jpg new file mode 100644 index 00000000..859e9d3c Binary files /dev/null and b/images/queenOfHearts.jpg differ diff --git a/images/queenOfSpades.jpg b/images/queenOfSpades.jpg new file mode 100644 index 00000000..e156c0f1 Binary files /dev/null and b/images/queenOfSpades.jpg differ diff --git a/images/sevenOfClubs.jpg b/images/sevenOfClubs.jpg new file mode 100644 index 00000000..df3fcff9 Binary files /dev/null and b/images/sevenOfClubs.jpg differ diff --git a/images/sevenOfDiamonds.jpg b/images/sevenOfDiamonds.jpg new file mode 100644 index 00000000..43afee5c Binary files /dev/null and b/images/sevenOfDiamonds.jpg differ diff --git a/images/sevenOfHearts.jpg b/images/sevenOfHearts.jpg new file mode 100644 index 00000000..4e9445e2 Binary files /dev/null and b/images/sevenOfHearts.jpg differ diff --git a/images/sevenOfSpades.jpg b/images/sevenOfSpades.jpg new file mode 100644 index 00000000..4a9728cc Binary files /dev/null and b/images/sevenOfSpades.jpg differ diff --git a/images/sixOfClubs.jpg b/images/sixOfClubs.jpg new file mode 100644 index 00000000..00835c22 Binary files /dev/null and b/images/sixOfClubs.jpg differ diff --git a/images/sixOfDiamonds.jpg b/images/sixOfDiamonds.jpg new file mode 100644 index 00000000..2ec74d3f Binary files /dev/null and b/images/sixOfDiamonds.jpg differ diff --git a/images/sixOfHearts.jpg b/images/sixOfHearts.jpg new file mode 100644 index 00000000..27caf392 Binary files /dev/null and b/images/sixOfHearts.jpg differ diff --git a/images/sixOfSpades.jpg b/images/sixOfSpades.jpg new file mode 100644 index 00000000..cba6e069 Binary files /dev/null and b/images/sixOfSpades.jpg differ diff --git a/images/tenOfClubs.jpg b/images/tenOfClubs.jpg new file mode 100644 index 00000000..78eefd8b Binary files /dev/null and b/images/tenOfClubs.jpg differ diff --git a/images/tenOfDiamonds.jpg b/images/tenOfDiamonds.jpg new file mode 100644 index 00000000..7c8d0ea9 Binary files /dev/null and b/images/tenOfDiamonds.jpg differ diff --git a/images/tenOfHearts.jpg b/images/tenOfHearts.jpg new file mode 100644 index 00000000..3350d602 Binary files /dev/null and b/images/tenOfHearts.jpg differ diff --git a/images/tenOfSpades.jpg b/images/tenOfSpades.jpg new file mode 100644 index 00000000..38dcfc6f Binary files /dev/null and b/images/tenOfSpades.jpg differ diff --git a/images/threeOfClubs.jpg b/images/threeOfClubs.jpg new file mode 100644 index 00000000..7fc9f2ea Binary files /dev/null and b/images/threeOfClubs.jpg differ diff --git a/images/threeOfDiamonds.jpg b/images/threeOfDiamonds.jpg new file mode 100644 index 00000000..f6c5f238 Binary files /dev/null and b/images/threeOfDiamonds.jpg differ diff --git a/images/threeOfHearts.jpg b/images/threeOfHearts.jpg new file mode 100644 index 00000000..c06feb6f Binary files /dev/null and b/images/threeOfHearts.jpg differ diff --git a/images/threeOfSpades.jpg b/images/threeOfSpades.jpg new file mode 100644 index 00000000..8b67a6d1 Binary files /dev/null and b/images/threeOfSpades.jpg differ diff --git a/images/twoOfClubs.jpg b/images/twoOfClubs.jpg new file mode 100644 index 00000000..40d9c58b Binary files /dev/null and b/images/twoOfClubs.jpg differ diff --git a/images/twoOfDiamonds.jpg b/images/twoOfDiamonds.jpg new file mode 100644 index 00000000..6e228385 Binary files /dev/null and b/images/twoOfDiamonds.jpg differ diff --git a/images/twoOfHearts.jpg b/images/twoOfHearts.jpg new file mode 100644 index 00000000..b0fe2159 Binary files /dev/null and b/images/twoOfHearts.jpg differ diff --git a/images/twoOfSpades.jpg b/images/twoOfSpades.jpg new file mode 100644 index 00000000..65cb6ad1 Binary files /dev/null and b/images/twoOfSpades.jpg differ diff --git a/index.html b/index.html index bbc7dffd..00f7b6d2 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,3 @@ -
@@ -8,148 +7,182 @@ - - - - - - - - - - + + + + + + + + + +
- Rocket Academy
-
- Input:
- -Output:
- ++ Computer +
++ Player +
+Game Result
+ - - - diff --git a/script.js b/script.js index bbe8a293..9cd288c6 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,208 @@ -var main = function (input) { - var myOutputValue = 'hello world'; - return myOutputValue; +var nums = [ + "ace", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "jack", + "queen", + "king", +]; +var suitsholder = ["Diamonds", "Hearts", "Clubs", "Spades"]; +var imgholder = []; +for (let i = 0; i < 13; i += 1) { + imgholder.push([]); + for (let j = 0; j < 4; j += 1) { + imgholder[i].push(`images/${nums[i]}Of${suitsholder[j]}.jpg`); + } +} +// creating a deck of cards +const makeDeck = () => { + var newDeck = []; + for (let i = 1; i <= 13; i += 1) { + var suits = ["♦", "♥", "♣", "♠"]; + for (let j = 0; j < suits.length; j += 1) { + var name = `${i}`; + if (name === "11") { + name = "Jack"; + } else if (name === "12") { + name = "Queen"; + } else if (name === "13") { + name = "King"; + } + var value = parseInt(name); + if (name === "Jack" || name === "Queen" || name === "King") { + value = 10; + } + + var card = { + value: value, + suit: suits[j], + img: imgholder[i - 1][j], + name, + }; + newDeck.push(card); + } + } + return newDeck; }; +// Get a random index ranging from 0 (inclusive) to max (exclusive). +const getRandomIndex = (max) => Math.floor(Math.random() * max); +// Shuffle an array of cards +const shuffleCards = (deck) => { + // Loop over the card deck array once + for (let currentIndex = 0; currentIndex < deck.length; currentIndex += 1) { + // Select a random index in the deck + const randomIndex = getRandomIndex(deck.length); + // Select the card that corresponds to randomIndex + const randomCard = deck[randomIndex]; + // Select the card that corresponds to currentIndex + const currentCard = deck[currentIndex]; + // Swap positions of randomCard and currentCard in the deck + deck[currentIndex] = randomCard; + deck[randomIndex] = currentCard; + } + // Return the shuffled deck + return deck; +}; + +//define global variables +var playerCardPlaceholders = document.getElementsByClassName("p-card"); +var computerCardPlaceholders = document.getElementsByClassName("c-card"); +var deck = makeDeck(); +var shuffledDeck = shuffleCards(deck); +var playButton = document.getElementById("play-button"); +var hitButton = document.getElementById("hit-button"); +var standButton = document.getElementById("stand-button"); +var restartButton = document.getElementById("restart-button"); +var outputMessageElement = document.getElementById("output"); + +var playerCards = []; +var computerCards = []; +var playerScore = 0; +var computerScore = 0; + +//defind helper functions +function checkBlackJacket(num1, num2) { + if ((num1 == 1 && num2 == 10) || (num1 == 10 && num2 == 1)) { + score = 21; + } else { + score = 0; + } + return score; +} + +function compareScore(num1, num2) { + var winner; + if ((num1 == 21 && num2 == 21) || (num1 > 21 && num2 > 21)) { + winner = "It's a draw!"; + } else if (num1 < 21 && num2 < 21) { + if (21 - num1 < 21 - num2) { + winner = "The winner is Player."; + } else if (21 - num1 > 21 - num2) { + winner = "The winner is Computer."; + } else { + winner = "It's a Draw!"; + } + } else if (num1 > 21 && num2 <= 21) { + winner = "The winner is Computer."; + } else if (num2 > 21 && num1 <= 21) { + winner = "The winner is Player."; + } + return winner; +} + +playButton.addEventListener("click", () => { + for (var i = 0; i < 2; i++) { + var card = shuffledDeck.pop(); + playerCards.push(card); + playerCardPlaceholders[i].src = card.img; + } + playerScore = checkBlackJacket(playerCards[0].value, playerCards[1].value); + + if (playerScore == 21) { + playerScore = playerScore; + } else { + playerScore = playerCards[0].value + playerCards[1].value; + } + + for (var i = 0; i < 2; i++) { + var card = shuffledDeck.pop(); + computerCards.push(card); + computerCardPlaceholders[i].src = card.img; + } + + computerScore = checkBlackJacket( + computerCards[0].value, + computerCards[1].value + ); + if (computerScore == 21) { + computerScore = computerScore; + } else { + computerScore = computerCards[0].value + computerCards[1].value; + } + + // Check if any player wins by Black Jacket + if (playerScore == 21 || computerScore == 21) { + if (playerScore == 21 && computerScore == 21) { + outputMessageElement.innerText = "Draw!"; + } else if (playerScore == 21) { + outputMessageElement.innerHTML = `Player wins by black jack!`; + } else { + outputMessageElement.innerHTML = `Computer wins by black jack!`; + } + } else { + outputMessageElement.innerHTML = ` Computer Points: ${computerScore}