Building a global counter variable?

Hi, I’m trying to build something extremely simple, a global counter variable for storing event logs. Basically everytime somebody hits the submit button, the counter increases by 1 and the corresponding value is inserted into a database. Something like this?

let globalcounter = 0;
onClick → globalcounter = globalcounter + 1;

The only problem is that the globalcounter in this case keeps resetting to 0 everytime the submit button is pressed. How do I solve this problem?

Hi Zain ,

If you placed the globalCounter inside the function, it will be reset to 0 each time you run that function.
So, be sure to place the let globalCounter = 0 ; at the top of the code.

Hope this helps!
Best,

Mustafa