The NodeList I have been using as a variable in functions has been working, but it it not working in the latest one on which I am working.
It gives an error "card is not defined." When I pass the variable into the function, it says it isn't iterable.
function matchCards() {
if(hand[0] === hand[1]) {
addPoint();
} else if(hand[0] != hand[1]) {
flipBack();
}
}
function flipBack (cards) {
for(card of cards) {
if(card.firstElementChild.src != "img/cardback.jpeg") {
for(const id of ids) {
document.querySelector(`[alt="${id}"]`).src = "img/cardback.jpeg";
console.log(document.querySelector(`[alt="${id}"]`).src);
hand = [];
changePlayer();
}
}
}
}
This is the global variable I'm trying to use:
const cards = document.getElementsByClassName("card");
This is a link to the whole project: https://codepen.io/ThomasBergman1987/pen/LqrJQM