Why is this code not working? I'm trying to do a simple timer. I want after pressing a button in HTML, the JavaScript function is triggered, which, through its variables, passes the number of seconds and the diva tag in which it will print the timer. The function should divide the number of the first variable by 60 (getting minutes and seconds in the remainder), write on the page, subtract 1 from the original number and repeat it with a delay of one second until the value of the variable = 0.
I tested this option both before and after writing the condition stopping the function, but it does not work. What's my mistake?
<script> function timer(tag,txt){ document.getElementById(tag).innerHTML+=txt/60 + '<br>'; txt = txt - 1; setTimeout(timer,1000); } </script> <div id="str"></div> <input type="button" onclick="timer('str',800)" value="ΠΠ°ΠΆΠΌΠΈ ΠΌΠ΅Π½Ρ" />
setTimeout(function() { timer(tag, txt); }, 1000);- Igor