A game attempt - updated project

First of all you can simplify your razzle function with a loop. Next, since you can grab the box’s id from your boxKey, you can use .querySelector to add some styles (or even better, a .highlight class):

const razzleEm = () => {

    for (let i=0; i<8; i++) {
        let newBox = boxKey[Math.floor(Math.random() * 180 + 1)];
        document.querySelector(`#${newBox.box}`).classList.add('highlight');
        dazzledSet.push(newBox);
    }
}

CSS:

.highlight {
  background:#888;
}

You’ll have to make some additional adjustments because you probably want to remove the .highlight class from all buttons when you razzle a second time.

1 Like