diff --git a/dom.js b/dom.js
new file mode 100644
index 00000000..4f0e7b3f
--- /dev/null
+++ b/dom.js
@@ -0,0 +1,48 @@
+var startGame = document.querySelector("#start-game");
+startGame.addEventListener("click", function () {
+ // Set result to input value
+ var input = document.querySelector("#input-field");
+ // Store the output of main() in a new variable
+ var result = main(input.value);
+
+ // Display result in output element
+ var output = document.querySelector("#output-div");
+ output.innerHTML = result;
+
+ // Reset input value
+ input.value = "";
+});
+var submit = document.querySelector("#submit-button");
+submit.addEventListener("click", function () {
+ // Set result to input value
+ var input = document.querySelector("#input-field");
+ // Store the output of main() in a new variable
+ var result = main(input.value);
+
+ // Display result in output element
+ var output = document.querySelector("#output-div");
+ output.innerHTML = result;
+
+ // Reset input value
+ input.value = "";
+});
+var drawButton = document.querySelector("#draw");
+drawButton.addEventListener("click", function () {
+ // Call the dealSingleCard function for the current player's hand
+ var result = dealSingleCard(playerProfile[currPlayer].cards);
+
+ // Update the output element with the result of dealing the card
+ var outputDiv = document.querySelector("#output-div");
+ outputDiv.innerHTML = result;
+});
+
+var standButton = document.querySelector("#stand");
+// Move the code to check playerCardValue and update the Stand button's display inside a function
+standButton.addEventListener("click", function () {
+ // Call the function to end the current player's turn
+ var output = endCurrPlayerTurn();
+
+ // Update the UI with the output message
+ var outputDiv = document.querySelector("#output-div");
+ outputDiv.innerHTML = output;
+});
diff --git a/index.html b/index.html
index bbc7dffd..4eefae10 100644
--- a/index.html
+++ b/index.html
@@ -1,155 +1,103 @@
-
+
-
-
You have drawn ${
+ playerCard.name
+ } of ${playerCard.suits}. ${displayPlayerCard(
+ hand
+ )} Your total card value is ${value} which is less than 17. Please draw again.`;
+ } else if (value >= 21) {
+ document.getElementById("draw").style.display = "none";
+ document.getElementById("submit-button").style.display = "";
+ document.getElementById("stand").style.display = "none";
+ submit.disabled = false;
+ endCurrPlayerTurn;
+ return `${playerProfile[currPlayer].name}'s turn:
You have drawn ${
+ playerCard.name
+ } of ${playerCard.suits}. ${displayPlayerCard(
+ hand
+ )} Your total card value is ${value}. Your turn has ended, press 'Next' to proceed.`;
+ } else if (value >= 17 && value < 21) {
+ drawButton.style.display = "";
+ standButton.style.display = "";
+ return `You have drawn ${playerCard.name} of ${
+ playerCard.suits
+ }. ${displayPlayerCard(
+ hand
+ )} Your total card value is ${value}. Please select to 'Draw' or 'Stand'`;
+ }
+};
+
+var dealCards = function () {
+ for (var a = 0; a < 2; a += 1) {
+ for (var b = 0; b < playerProfile.length; b += 1) {
+ dealSingleCard(playerProfile[b].cards);
+ }
+
+ dealSingleCard(computerCardArray);
+ }
+};
+
+// Start a new round-- change mode and reset currplayer index
+
+var endCurrPlayerTurn = function () {
+ var output = ``;
+ if (currPlayer == numOfPlayers - 1) {
+ gameMode = computerDraw;
+ document.getElementById("submit-button").style.display = "";
+ document.getElementById("stand").style.display = "none";
+ document.getElementById("draw").style.display = "none";
+ output = `You have drawn ${displayPlayerCard(
+ playerProfile[numOfPlayers - 1].cards
+ )} Your total score is ${detValue(
+ playerProfile[numOfPlayers - 1].cards
+ )}
Results: `;
+ var anyPlayerWon = false;
+ for (var f = 0; f < playerProfile.length; f += 1) {
+ var currentPlayer = playerProfile[f];
+ var currentPlayerValue = detValue(currentPlayer.cards);
+ playerHasBj = detBlackjack(currentPlayer.cards);
+ console.log(playerHasBj);
+ console.log(currentPlayer.cards);
+ // Computer hits blackjack
+
+ if (computerHasBj == true && playerHasBj == true) {
+ output += ` Dealer has Blackjack and ${currentPlayer.name} also has Blackjack! It's a tie! Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+ } else if (computerHasBj == true && playerHasBj == false) {
+ computerWinCounter += 1;
+ output += ` Dealer has Blackjack! ${currentPlayer.name} has lost against dealer! Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+ }
+ // player hits blackjack
+ else if (computerHasBj == false && playerHasBj == true) {
+ currentPlayer.wins++;
+ output += ` ${currentPlayer.name} has Blackjack and won against the dealer! Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+
+ // no blackjack
+ } else if (currentPlayerValue > 21) {
+ // Player busts
+ computerWinCounter++;
+ output += `${currentPlayer.name} has busted. Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+ }
+ // Player wins
+ else if (
+ currentPlayerValue <= 21 &&
+ (currentPlayerValue > computerCardValue || computerCardValue > 21)
+ ) {
+ currentPlayer.wins++;
+ output += `${currentPlayer.name} has won against the dealer! Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+ anyPlayerWon = true;
+ }
+ // Player ties
+ else if (
+ currentPlayerValue <= 21 &&
+ currentPlayerValue === computerCardValue
+ ) {
+ output += `${currentPlayer.name} has tied with the dealer. Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+ }
+ // Player loses
+ else {
+ computerWinCounter++;
+ output += `${currentPlayer.name} has lost to the dealer. Total ${currentPlayer.name}'s wins: ${currentPlayer.wins}
`;
+ }
+ }
+ resetGame();
+ return output + " Please click next to play again!";
+ }
};