I want a variable's value regularly changing between 0 and 1. If I have a variable whose value is 0 (counter = 0
), how can I increase it by 1 (counter = 1
) after a few seconds, then decrease it back to 0 ( counter = 0
) after another few seconds? An endless loop basically is what I want.
I'm assuming this will require setTimeout or setInterval, but I've absolutely no idea how I'd go about this. I'm very unfamiliar with the syntax; I'm very much a newbie. Does anyone have any pointers?
Thanks!