mirror of
https://github.com/MrEidam/Black-Jack.git
synced 2025-12-29 17:06:11 +00:00
Added alerts
This commit is contained in:
@@ -11,11 +11,11 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<article class="cards cards1"><img src="./BlackJackCards/J-B.png" class="card" alt=""></article>
|
<article class="cards cards1"><img src="./BlackJackCards/J-B.png" class="card" alt=""></article>
|
||||||
<h2 id="playerScore">69</h2>
|
<h2 id="playerScore">0</h2>
|
||||||
<article id="playerHand" class="cards cards2"></article>
|
<article id="playerHand" class="cards cards2"></article>
|
||||||
<section>
|
<section>
|
||||||
<button onclick="hit()">Hit</button>
|
<button onclick="hit()">Hit</button>
|
||||||
<button>Stand</button>
|
<button onclick="stand()">Stand</button>
|
||||||
</section>
|
</section>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
15
main.js
15
main.js
@@ -102,7 +102,7 @@ function addScore(num){
|
|||||||
score += isNaN(e) ? 10 : parseInt(e);
|
score += isNaN(e) ? 10 : parseInt(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
document.querySelector('h2').innerHTML = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reshuffle(){
|
function reshuffle(){
|
||||||
@@ -119,6 +119,7 @@ function createCard(imgSource){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cardAvail(num){
|
function cardAvail(num){
|
||||||
|
if(score>21) return;
|
||||||
const availableCards = ['Clubs', 'Diamonds', 'Hearts', 'Spades'].filter((suit, idx) => num[idx] > 0);
|
const availableCards = ['Clubs', 'Diamonds', 'Hearts', 'Spades'].filter((suit, idx) => num[idx] > 0);
|
||||||
|
|
||||||
// Check if there are any available cards
|
// Check if there are any available cards
|
||||||
@@ -161,10 +162,22 @@ function addCard(){
|
|||||||
reshuffle();
|
reshuffle();
|
||||||
}
|
}
|
||||||
cardAvail(cardsleft());
|
cardAvail(cardsleft());
|
||||||
|
if(score > 21){
|
||||||
|
alert("You lost");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hit(){
|
function hit(){
|
||||||
addCard();
|
addCard();
|
||||||
|
if(score === 21){
|
||||||
|
alert("BLACKJACK!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function stand(){
|
||||||
|
document.getElementById('playerHand').innerHTML = "";
|
||||||
|
score = 0;
|
||||||
|
playerCards = [];
|
||||||
document.querySelector('h2').innerHTML = score;
|
document.querySelector('h2').innerHTML = score;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user