diff --git a/blackjack-game-main/README.md b/blackjack-game-main/README.md new file mode 100644 index 0000000..b72f403 --- /dev/null +++ b/blackjack-game-main/README.md @@ -0,0 +1,26 @@ +# BlackJack-Game Website + +## Description +This is a simple web application that helps in playing blackjack. It was created by following a tutorial from FreeCodeCamp. + +## Features +- **Start a game**: Allows users to pick a card. +- **Get a new card**: Users can get a new card and if the total exceeds 21 they are out of the game. +- **Reset functionality**: Resets the count back to zero. + +## How to Use +1. Open the website. +2. Click the 'Start Game' button to start the game and get a card. +3. Use the 'New Card' button to get a new card. +4. If the total points exceed 21 the user is out of the game. + +## Built With +- HTML +- CSS +- JavaScript + +## Acknowledgements +- This project was built by following a FreeCodeCamp tutorial. + +## Author +- Anant Jain diff --git a/blackjack-game-main/index.html b/blackjack-game-main/index.html new file mode 100644 index 0000000..5121033 --- /dev/null +++ b/blackjack-game-main/index.html @@ -0,0 +1,18 @@ + + + + + + Blackjack game + + + +

Blackjack

+

Want to play a round?

+

Cards:

+

Sum:

+ + + + + \ No newline at end of file diff --git a/blackjack-game-main/script.js b/blackjack-game-main/script.js new file mode 100644 index 0000000..9600a0c --- /dev/null +++ b/blackjack-game-main/script.js @@ -0,0 +1,58 @@ +let cards=[]; +let sum = 0; +let hasBlackJack = false; +let isAlive = false; +let message = ""; +let messageEl = document.getElementById("message-el"); +let sumEl = document.getElementById("sum-el"); +let cardsEl = document.getElementById("cards-el"); + + +function getRandomCard(){ + let randomNumber= Math.floor(Math.random()*13)+1; + if(randomNumber===1){ + return 11; + } + else if(randomNumber>10){ + return 10; + } + else{ + return randomNumber; + } +} + + +function renderGame() { + cardsEl.textContent = "Cards: "; + for (let i=0;i