Newbie here. Trying to create a blackjack game in javascript. I stored my cards in an array of objects(type, suit, and value) and have gotten it to work so that when I click 'New game' I get a random card on each div.
*I can't seem to get each card to show up a different random card. Whenever I reload the page, the same random card pops up on all 4 divs. Can someone help me out here? * My code below...After I store the array of objects here is what I have.
var randomNumber = Math.floor(Math.random() * 52)
var randomCard = deck[randomNumber];
var playerCardOne = document.querySelector('.playerCardOne');
var playerCardTwo = document.querySelector('.playerCardTwo');
var dealerCardOne = document.querySelector('.dealerCardOne');
var dealerCardTwo = document.querySelector('.dealerCardTwo');
document.querySelector("#newGame").addEventListener("click", function (){
var cardHTML = '';
cardHTML += '<h1>' + randomCard.cardType + '/h1>' + '<h2>' + randomCard.suitType + '</h2>'
// cardHTML += ".playerCardTwo" + randomCard.cardType + ".playerCardTwo";
// cardHTML += ".dealerCardOne" + randomCard.cardType + ".dealerCardTwo";
// cardHTML += ".dealerCardTwo" + randomCard.cardType + ".dealerCardTwo";
// cardHTML += '<h2>' + randomCard.suitType + '</h2>';
cardHTML = '<h1>' + randomCard.cardType + '</h1>' + '<h2>' + randomCard.suitType + '</h2>'
playerCardOne.innerHTML = cardHTML;
playerCardTwo.innerHTML = cardHTML;
dealerCardOne.innerHTML = cardHTML;
dealerCardTwo.innerHTML = cardHTML;
})
console.log(randomCard);