1

I study this code below. This code is about memory game, it displays cards on the page

const deck = document.querySelector('.deck');
shuffledCards = shuffle(cards);)

function displayShuffledCards(){
  for (var i= 0; i < shuffledCards.length; i++){
      [].forEach.call(shuffledCards, function(item){
        deck.appendChild(item);
      });
  }
}

displayShuffledCards();

and I know what it exactly does but I don't understand enough what this part below do. I will be grateful if you could explain these two lines.

({
      [].forEach.call(shuffledCards, function(item){
        deck.appendChild(item);
      });
  }
  • 1
    you should pass `deck` as a param to the `displayShuffleCards` method first - this is a better pattern. You try to iterate over `shuffledCards` (which should also be passed as an argument to the method) and append each card to `deck` . I prefer the following syntax: `shuffledCards.forEach((item) => { deck.appendChild(item) }`. This will do the same as your 2 lines of code – messerbill Mar 02 '19 at 12:58

0 Answers0