does anybody know why my counter keep counting from the beginning since i hit resume button?
var minute;
var second;
var audio;
var interval;
var button = HTMLButtonElement.value = "Resume"
function yok() {
document.getElementById("btninput").disabled = true
minute = document.getElementById("minute").value
second = document.getElementById("second").value
interval = setInterval(tambah, 1000)
function tambah() {
second--
if (minute != 0 && second == -1) {
minute--
second = 59
} else if (minute == 0 && second == 0) {
clearInterval(interval)
document.getElementById("hasill").innerHTML = "Finish!!!"
document.getElementById("btninput").disabled = false
}
document.getElementById("hasil").innerHTML = minute + " : " + second
}
}
function stop() {
document.getElementById("btninput").disabled = false
clearInterval(interval)
document.getElementById("btninput").innerHTML = button;
}
<p data-component="head">TIMER</p>
<input type="number" id="minute" placeholder="minute" style="width: 65px;" data-component="minute">
<input type="number" id="second" placeholder="seconds" style="width: 69px;" max="60" data-component="second">
<p id="hasil" data-component="hasil">00</p>
<p id="hasill" data-component="hasill"></p>
<audio src="ding-sound-effect_2.mp3" id="sound" data-component="sound"></audio>
<button onclick="yok()" data-component="button" id="btninput">start</button>
<button onclick="stop()" id="stop">stop</button>
's remove from one
– Imran Rafiq Rather Apr 15 '20 at 07:03