class ScoreDisplay extends HTMLElement { static get observedAttributes() { return ['score']; } constructor() { super(); this.attachShadow({ mode: 'open' }); this.score = 0; } connectedCallback() { this.render(); } attributeChangedCallback(name, oldValue, newValue) { if (name === 'score') { this.score = newValue; this.render(); } } render() { this.shadowRoot.innerHTML = `

SCORE

${this.score}

`; } } customElements.define('custom-score-display', ScoreDisplay);