Answer the question
In order to leave comments, you need to log in
Randomizer function for displaying items on the screen. How to implement?
There is an array of objects, where each object is a playing card that is displayed on the screen when a button is pressed. Only one card can be on the screen. Accordingly, when the button is pressed, the previous one is deleted, and the new one is drawn. You need to make sure that the same cards are not displayed until all have been displayed, and then clear the data and display them again.
How to check if a card has been withdrawn? Now I do this:
createNewCard(cards[chooseCard()]);
where createNewCard draws a card and throws a random number from chooseCard into it:
function chooseCard() {
let cardNum = Math.floor(Math.random() * cards.length);
return cardNum;
}
function chooseCard() {
let cardNum = Math.floor(Math.random() * cards.length);
let shownCards = [];
for (key of shownCards) {
if (key !== cardNum) {
shownCards.push(cardNum);
} else {
cardNum = Math.floor(Math.random() * cards.length);
}
return cardNum;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question