I have this script
var x = 0;
document.addEventListener('DOMContentLoaded', function() {
const button = document.getElementById('my-button')
button.addEventListener('click', () => myFunction(x));
});
function myFunction(x) {
console.log(x)
x++
}
I need that when I click the button, myFunction receives the current value of x and not the value that was assigned when the function was added (0 in this case), the thing is that I have another function that is constantly updating the value of x, but if console.log the value of x within myFunction I always get 0. Probably there is a straightforward solution but I'm really struggling with this and my skills with JS are very limited.