I'm busy building a memory game in JavaScript.
While following a tutorial online I had to use this code:
function startGame() {
var shuffledCards = shuffle(cards);
for (let i = 0; i < shuffledCards.length; i++) {
[].forEach.call(shuffledCards, function (item) {
deck.appendChild(item);
});
}
}
and I don't really understand what is happening with this part to be exact. (could someone please explain this part?)
[].forEach.call(shuffledCards, function (item) {
deck.appendChild(item);
});
I'm wrote the code below, which I understand much better:
function startGame() {
var shuffledCards = shuffle(cards);
for (let i = 0; i < shuffledCards.length; i++) {
deck.appendChild(shuffledCards[i]);
}
}
So why would I use the above code as apposed to the code I wrote? And could someone please take me through what is happening in the above code too. My brain gets fried when I'm trying to make sense of it.