Below is the code snippet, on line number 18 and 22 where I have set the style property, it is giving the error cannot read property of undefined but I’m creating the element as div inside the constructor and appending the tile class still it is giving the error
export default class Tile {
#tileElement
#x
#y
#value
contructor(tileContainer, value = Math.random() > 0.5 ? 2 : 4) {
this.#tileElement = document.createElement('div')
this.#tileElement.classList.add('tile')
tileContainer.append(this.#tileElement)
this.#value = value
}
set value(v) {
this.#value = v
this.#tileElement.textContent = v
}
set x(value) {
this.#x = value
this.#tileElement.style.setProperty('--x', value)
}
set y(value) {
this.#y = value
this.#tileElement.style.setProperty('--y', value)
}
}