From 08240fa8376cbc8ca82019839322b7e9a17533ae Mon Sep 17 00:00:00 2001 From: Tshidy Date: Sun, 7 Apr 2024 16:23:53 +0200 Subject: [PATCH] Limited function to work on certain conditions --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index a733ddb..5bff40e 100644 --- a/index.js +++ b/index.js @@ -53,11 +53,16 @@ startBtn.addEventListener("click", startGame); let newBtn = document.querySelector("#new-btn"); function newCard() { - let newCard = getRandomCard(); - sum += newCard; //adding a number to an existing variable - //Push new card to the cards array - cards.push(newCard); - console.log(cards); - renderGame(); + //Shoudn't be able to draw cards when isAlive = false + //Should'nt be allowed to start the game with one card + //Only allow the player to get a new card if she isAlive and does not have BlackJack + if (isAlive === true && hasBlackJack === false) { + let newCard = getRandomCard(); + sum += newCard; //adding a number to an existing variable + //Push new card to the cards array + cards.push(newCard); + console.log(cards); + renderGame(); + } } newBtn.addEventListener("click", newCard);