I am not proficient in Javascript. I am trying to set a timer for 5 minutes for a workout activity. However, when i press the play button, the timer decreases but when i press the play button again, it overlaps with the current timer.
How do i pause the timer and only allow it to be clicked once? Should i set another button for pause? This is the code:
<!--JS for timer countdown, have to find a way to prevent button from keep pressing-->
<script type="text/javascript">
function startTimer() {
var btton = document.getElementById('start')
var min = 0;
var sec = 59;
setInterval(function () {
document.getElementById("timer").innerHTML = min + ":" + sec;
sec--;
if (sec == -1) {
min--;
sec = 59;
}
if (min == -1) {
clearTimeout();
}
if (sec < 10) {
sec = "0" + sec;
}
}, 1000);
}
</script>
<div id="timer">
<div id="time">5:00</div>
</div>
<img id="start" src="../img/icons/play-button.png" onclick="return startTimer()">