view my code
This code doesn't work if I put variable x outside the function like this. In this case, it wouldn't alert my input value, but the initial value which is null in this case. The error is fixed if I put x inside the function. Does anyone know why?
Thanks so much!