I keep getting this error and I'm not sure what to do? I'm trying to make a flip card game. Uncaught TypeError: Cannot read property 'getAttribute' of undefined at flipCard (main.js:42) at createBoard (main.js:53) at main.js:59나는 자바 스크립트에 새로 온 사람과 내가
var cards = [
{
rank: 'queen',
suit: 'diamonds',
cardImage: 'images/queen-of-diamonds.png'
},
{
rank: 'queen',
suit: 'hearts',
cardImage: 'images/queen-of-hearts.png'
},
{
rank: 'king',
suit: 'diamonds',
cardImage: 'images/king-of-diamonds.png'
},
{
rank: 'king',
suit: 'hearts',
cardImage: 'images/king-of-hearts.png'
}
]
var cardsInPlay = [cards]
var checkForMatch = function() {
this.cardImage.setAttribute(src)
if (cardsInPlay[0] === cardsInPlay[1]) {
window.alert('You found a match!')
} else {
window.alert('Sorry, try again')
}
}
var flipCard = function (cardId) {
this.cardId.getAttribute('data-id')
checkForMatch()
console.log('User flipped ' + cards[cardId].rank)
console.log('User flipped ' + cards[cardId].cardImage)
console.log('User flipped ' + cards[cardId].suit)
}
function createBoard() {
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())
cardElement.appendChild(game-board)
}
}
createBoard()
cardsInPlay.push(cards[cardId])`