This question already has an answer here:
What I'm building:
Hey guys! I'm trying to build a memory game, where you match the cards as you turn them over.
Problem:
The first step appears to be getting these unordered list items into some kind of data structure and randomising them. How do I do this in plain JS?
Attempted
I've tried to create an array to store the data but I can't seem to get it to log anything to the console. I'm also unsure if an array is the best way to do this. Any suggestions are welcome :)
const cardDeck = document.querySelectorAll('card');
Array.from(cardDeck).forEach(function(card){
console.log(card);
});
<ul class="deckOfCards">
<li class="card">
<i class="genericCard"></i>
</li>
<li class="card">
<i class="genericCard"></i>
</li>
<li class="card">
<i class="genericCard"></i>
</li>
<li class="card">
<i class="genericCard"></i>
</li>
<li class="card">
<i class="genericCard"></i>
</li>
<li class="card">
<i class="genericCard"></i>
</li>
</ul>
Aucun commentaire:
Enregistrer un commentaire