I am making a simple calculator using html and Javascript. Here is the code that is working and updating the calculator display when the button is clicked.

```
const display = document.querySelector('#display');

const cells = document.querySelectorAll('.cell');
cells.forEach((cell) => {
    cell.addEventListener('click', (e) => {
        if (e.target.value !== NaN) {
            a = e.target.value;
        } else {
            a = parseInt(e.target.value, 10);
        };
        display.textContent += a + ' ';
    });
});

```

I am trying to save the button value into a global variable so I can use it later in math operations as shown below. I declared a global variable x and tried to update it when the buttons are clicked.

```
const display = document.querySelector('#display');

let x;

const cells = document.querySelectorAll('.cell');
cells.forEach((cell) => {
    cell.addEventListener('click', (e) => {
        if (e.target.value !== NaN) {
            a = e.target.value;
            x = a;
        } else {
            a = parseInt(e.target.value, 10);
            x = a;
        };
        display.textContent += a + ' ';
    });
});

console.log(x);

```

The display.textContent is working as intended but console.log(x) isn't updating when the buttons are clicked. How do I update the variable x with button.value?