const cardChild = document.querySelectorAll('.card i');
const cardsArray = ['a','a','b','b','c','c'];
const matchArray = [];
function cardsToClass() {
for (i = 0; i < cardChild.length; i++) {
let newCard = cardsArray.pop();
let newCardClass = cardChild[i];
matchArray.push(cardsArray[i]);
newCardClass.className += newCard;
console.log(cardsArray);
}; }
Hello friends! The code above showcases a function that utilizes .pop() to assign elements from 'cardsArray' as classes in a DOM element. The goal is to have two arrays ('cardsArray' and 'matchArray') with identical contents. We are almost there, but when I check 'matchArray', it seems off:
['a','b','c',undefined,undefined,undefined]
I suspect the issue might be at:
matchArray.push(cardsArray[i]);
However, I'm not entirely sure. Any insights into why it's not capturing the duplicate elements?
Thank you!