From ed91a4e0e9598ce2ab3346b36dad161543023973 Mon Sep 17 00:00:00 2001 From: MrEidam Date: Sat, 5 Oct 2024 23:52:22 +0200 Subject: [PATCH] Added alerts --- index.html | 4 ++-- main.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 54c46af..ba03080 100644 --- a/index.html +++ b/index.html @@ -11,11 +11,11 @@
-

69

+

0

- +
diff --git a/main.js b/main.js index 8e62cd8..157e0f0 100644 --- a/main.js +++ b/main.js @@ -102,7 +102,7 @@ function addScore(num){ score += isNaN(e) ? 10 : parseInt(e); } }); - + document.querySelector('h2').innerHTML = score; } function reshuffle(){ @@ -119,6 +119,7 @@ function createCard(imgSource){ } function cardAvail(num){ + if(score>21) return; const availableCards = ['Clubs', 'Diamonds', 'Hearts', 'Spades'].filter((suit, idx) => num[idx] > 0); // Check if there are any available cards @@ -161,10 +162,22 @@ function addCard(){ reshuffle(); } cardAvail(cardsleft()); + if(score > 21){ + alert("You lost"); + } } function hit(){ addCard(); + if(score === 21){ + alert("BLACKJACK!") + } +} + +function stand(){ + document.getElementById('playerHand').innerHTML = ""; + score = 0; + playerCards = []; document.querySelector('h2').innerHTML = score; } \ No newline at end of file