Skip to content
Snippets Groups Projects
Commit 2bebaeb5 authored by Jonathan Vitale's avatar Jonathan Vitale
Browse files

Add code for tutorial 3

parent d2d7823f
No related branches found
Tags tutorial-3
No related merge requests found
const gameState = { const gameState = {
playerWallet: 100, playerWallet: 100,
currentBet: null currentBet: null,
cards: [[], []]
} }
function collectBet(){ function collectBet(){
...@@ -22,10 +23,26 @@ function collectBet(){ ...@@ -22,10 +23,26 @@ function collectBet(){
return currentBet; return currentBet;
} }
function drawCard(){
let min = 2;
let max = 11;
let rndNum = min + Math.floor(Math.random()*(max - min + 1 ));
return rndNum;
}
function blackjack(){ function blackjack(){
// decide the bet, collect it // decide the bet, collect it
gameState.currentBet = collectBet(); gameState.currentBet = collectBet();
for(let playerIndex = 0; playerIndex < gameState.cards.length; playerIndex++){
for(let cardIndex = 0; cardIndex < 2; cardIndex++){
gameState.cards[playerIndex][cardIndex] = drawCard();
}
}
console.log(gameState.cards);
// we deal the first 2 cards for the player // we deal the first 2 cards for the player
// check immediately that the player has blackjack // check immediately that the player has blackjack
// if so, we need to pay 2.5 the bet -> end the game // if so, we need to pay 2.5 the bet -> end the game
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment