I’m trying to make a button that changes a global variable.
HTML
<script src='script.js'><script>
<button onclick = "myFunction(a)>Increase A</button>
<button onclick = "myFunction(b)>Increase B</button>
JavaScript
var a = 0;
var b = 0;
function myFunction(variable){
variable += 1;
}
I’m trying to make a/b increase, but it doesn’t have any effect. I think it is only changing a copy of the variable. Is it possible to fix this?
Edit: It doesn’t seem to work for let
. Is it possible with let
as well?