Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Why is the console saying flipCard is not defined?

I apologize is this is formatted wrong.

I'm in the process of creating a Memory Game and its driving nuts that the console keeps saying "flipCard is not defined". Please help.

var flipCard = function () {
   var cardId = this.getAttribute('data-id');

   cardsInPlay.push (cards[cardId].rank);

   this.setAttribute('src', cards[cardId].cardImage);

   if (cardsInPlay.length === 2);
       checkForMatch ();
   };

   console.log ("User flipped " + cards[cardId].rank);
   console.log (cards[cardId].cardImage);
   console.log (cards[cardId].suit);
}

var createBoard = function() {
   for(var i = 0; i < cards.length; i++) {
      var cardElement = document.createElement('img');

      cardElement.setAttribute('src',"images/back.png");
      cardElement.setAttribute('data-id', i);
      cardElement.addEventListener('click', flipCard());

      document.getElementById('game- 
      board').appendChild(cardElement);
   }
}

Comments