diff --git a/index.html b/index.html
index bbc7dffd..81ae3fcf 100644
--- a/index.html
+++ b/index.html
@@ -1,4 +1,3 @@
-
@@ -8,41 +7,83 @@
+
♠️♥️♣️♦️
+
Game instructions
+
Your goal: Beat the dealer without going over 21
+
+
+ You and the dealer will be dealt 2 cards each. Choose 'h' to hit or 's'
+ to stand.
+
+
+ Dealer must hit if their hand is 16 or less, otherwise, it must stand.
+
+
+ Aces can be 1 or 11. Blackjack is an Ace and a 10-value card. It beats
+ any other hand totalling 21.
+
+
Click "Submit" to start! Good luck!
+
♠️♥️♣️♦️
+
diff --git a/script.js b/script.js
index bbe8a293..2101b983 100644
--- a/script.js
+++ b/script.js
@@ -1,4 +1,289 @@
-var main = function (input) {
- var myOutputValue = 'hello world';
+///// Global variables/////
+
+let playerHand = [];
+let computerHand = [];
+
+let state = "Draw cards for both";
+
+///// Global functions/////
+
+// Function to create a deck of 52 cards
+let makeDeck = function () {
+ // Initialise an empty deck array
+ let cardDeck = [];
+ // Initialise an array of the 4 suits in our deck. We will loop over this array.
+ let suits = ["♥️", "♦️", "♣️", "♠️"];
+
+ // Loop over the suits array
+ let suitIndex = 0;
+ while (suitIndex < suits.length) {
+ // Store the current suit in a variable
+ let currentSuit = suits[suitIndex];
+ let rankCounter = 1;
+ while (rankCounter <= 13) {
+ // By default, the card name is the same as rankCounter
+ let cardName = rankCounter;
+ // If rank is 1, 11, 12, or 13, set cardName to the ace or face card's name
+ if (cardName == 1) {
+ cardName = "Ace";
+ } else if (cardName == 11) {
+ cardName = "Jack";
+ } else if (cardName == 12) {
+ cardName = "Queen";
+ } else if (cardName == 13) {
+ cardName = "King";
+ }
+ // If name is Jack, Queen and King, set cardRank to 10 points
+ let cardRank = 0;
+ if (cardName == "Jack" || cardName == "Queen" || cardName == "King") {
+ cardRank = 10;
+ } else {
+ cardRank = rankCounter;
+ }
+ // Create a new card with the current name, suit, and rank
+ let card = {
+ name: cardName,
+ suit: currentSuit,
+ rank: cardRank,
+ };
+ // Add the new card to the deck
+ cardDeck.push(card);
+ // Increment rankCounter to iterate over the next rank
+ rankCounter += 1;
+ }
+ // Increment the suit index to iterate over the next suit
+ suitIndex += 1;
+ }
+ // Return the completed card deck
+ return cardDeck;
+};
+
+// Function to shuffle the deck
+let getRandomIndex = function (max) {
+ return Math.floor(Math.random() * max);
+};
+
+// Shuffle the elements in the cardDeck array
+var shuffleCards = function (cardDeck) {
+ // Loop over the card deck array once
+ var currentIndex = 0;
+ while (currentIndex < cardDeck.length) {
+ // Select a random index in the deck
+ var randomIndex = getRandomIndex(cardDeck.length);
+ // Select the card that corresponds to randomIndex
+ var randomCard = cardDeck[randomIndex];
+ // Select the card that corresponds to currentIndex
+ var currentCard = cardDeck[currentIndex];
+ // Swap positions of randomCard and currentCard in the deck
+ cardDeck[currentIndex] = randomCard;
+ cardDeck[randomIndex] = currentCard;
+ // Increment currentIndex
+ currentIndex = currentIndex + 1;
+ }
+ // Return the shuffled deck
+ return cardDeck;
+};
+let shuffledDeck = shuffleCards(makeDeck());
+
+//Function to check for blackjack
+let checkBlackJack = function (hand) {
+ let hasBlackJack = false;
+ let hasTen = false;
+ let hasAce = false;
+
+ for (position = 0; position < hand.length; position += 1) {
+ if (hand[position].rank == "10") {
+ hasTen = true;
+ }
+ if (hand[position].name == "Ace") {
+ hasAce = true;
+ }
+ if (hasTen && hasAce) {
+ hasBlackJack = true;
+ console.log("black jack");
+ }
+ return hasBlackJack;
+ }
+};
+
+// Function to calculate sum of cards
+let getSum = function (handarray) {
+ let sum = 0; // Auto reset each time
+ let hasAce = false;
+
+ // Loop to count cards in hand
+ for (let sumCounter = 0; sumCounter < handarray.length; sumCounter += 1) {
+ sum = sum + handarray[sumCounter].rank;
+ if (handarray[sumCounter].rank == 1) {
+ hasAce = true;
+ }
+ }
+ // Ace is read as 11 if hand is less 21 or less
+ // Ace is read as 1 by default
+ if (sum + 10 < 22 && hasAce) {
+ // Adding 10 to the sum first to check if the hand > 21
+ sum = sum + 10;
+ }
+ return sum;
+};
+
+// Function to calculate sum of cards
+let showHandCards = function (hand) {
+ let handOutput = "";
+ for (counter = 0; counter < hand.length; counter += 1) {
+ handOutput += hand[counter].name + " " + hand[counter].suit;
+ if (counter != hand.length - 1) {
+ handOutput += " , "; // no commas after the last card
+ }
+ }
+ return handOutput;
+};
+
+// Function to output message for PLAYER card sum and the cards
+let showPlayerMessage = function (hand) {
+ myOutputValue = `Your hand: