From d2d7823f583a861d92f7faa380e7973bd65dab56 Mon Sep 17 00:00:00 2001
From: Jonathan Vitale <jvitale@une.edu.au>
Date: Thu, 10 Nov 2022 13:59:15 +1100
Subject: [PATCH] Update code for tutorial 2

---
 game-logic.js | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/game-logic.js b/game-logic.js
index b54d397..5ada932 100644
--- a/game-logic.js
+++ b/game-logic.js
@@ -1,5 +1,30 @@
+const gameState = {
+    playerWallet: 100,
+    currentBet: null
+}
+
+function collectBet(){
+    let currentBet;
+    let isValidBet = false;
+    //let counter = 0;
+    do {
+        console.log("please provide your bet")
+        currentBet = 10; // mocking up with a value
+        console.log(`You provided the bet being ${currentBet}`);
+        if (currentBet <= 0 || currentBet > gameState.playerWallet){
+            console.log('Your bet is not valid!');
+            //counter++;
+        } else {
+            isValidBet = true;
+        }
+    } while(!isValidBet) //&& counter < 4);
+
+    return currentBet;
+}
+
 function blackjack(){
     // decide the bet, collect it
+    gameState.currentBet = collectBet();
 
     // we deal the first 2 cards for the player
     // check immediately that the player has blackjack
@@ -29,4 +54,6 @@ function blackjack(){
     // if player's score > dealer's score: player wins
     //    -> pay 2 times the bet
     // end the game
-}
\ No newline at end of file
+}
+
+blackjack();
\ No newline at end of file
-- 
GitLab