diff --git a/Untitled-1.css b/Untitled-1.css new file mode 100644 index 0000000..e40c6d7 --- /dev/null +++ b/Untitled-1.css @@ -0,0 +1,31 @@ + + +body { + font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', Arial, sans-serif; + background-image: url("images/table.png"); + background-size: cover; + font-weight: bold; + color: white; + text-align: center; +} + +h1 { + color: goldenrod; +} + +#message-el { + font-style: italic; +} + +button { + color: #016f32; + width: 150px; + background: goldenrod; + padding-top: 5px; + padding-bottom: 5px; + font-weight: bold; + border: none; + border-radius: 2px; + margin-bottom: 2px; + margin-top: 2px; +} \ No newline at end of file diff --git a/index.html b/index.html index e286358..625cf49 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,21 @@ + BlackJack ♠️♥️♦️♣️ - - +

Blackjack

+

Want to play a round?

+

Cards:

+

Sum:

+ + +

+ + diff --git a/index.js b/index.js index 1bb5589..5fffc13 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,70 @@ -// 1. Create two variables, firstCard and secondCard. -// Set their values to a random number between 2-11 -// 2. Create a variable, sum, and set it to the sum of the two cards +let player = { + name: "Per", + chips: 200 +} -let firstCard = 6 -let secondCard = 9 -let sum = firstCard + secondCard +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") +let playerEl = document.getElementById("player-el") -console.log(sum) \ No newline at end of file +playerEl.textContent = player.name + ": $" + player.chips + +function getRandomCard() { + let randomNumber = Math.floor( Math.random()*13 ) + 1 + if (randomNumber > 10) { + return 10 + } else if (randomNumber === 1) { + return 11 + } else { + return randomNumber + } +} + +function startGame() { + isAlive = true + let firstCard = getRandomCard() + let secondCard = getRandomCard() + cards = [firstCard, secondCard] + sum = firstCard + secondCard + renderGame() + +} + +function renderGame() { + cardsEl.textContent = "Cards: " + for (let i = 0; i < cards.length; i++) { + cardsEl.textContent += cards[i] + " " + } + + + sumEl.textContent = "Sum: " + sum + if (sum <= 20) { + message = "Do you want to draw a new card?" + } else if(sum === 21) { + message = "You've got Blackjack!" + hasBlackjack = true + } else if(sum > 21) { + message = "You're out of the game!" + isAlive = false + } + + messageEl.textContent = message +} + + +function newCard() { + if (isAlive === true && hasBlackJack === false) { + let card = getRandomCard() + sum += card + cards.push(card) + renderGame() + } +}