My question here is how to pause and resume at the interval with a single button. My pause function shows it but it does not work, I want to put false and then pass it to true and when it is true to re-activate the interval, I wanted to do something similar to what is commented below, but it does not fit. Thanks
<!DOCTYPE html>
<html lang="es">
<head>
<title>Objeto Window</title>
<meta charset="UTF8"/>
<link rel="stylesheet" href="clearInterval.css">
<body>
<div class="bigBox">
<!-- <button onclick="start()" id="start"type="button" name="button">START</button> -->
<button onclick="desactivar()" id="desactivar"type="button" name="button">DESACTIVAR</button>
<button onclick="ReStartFunction()" id="restart"type="button" name="button">RESTART</button>
<button onclick="pause()"id="pause"type="button" name="button">PAUSAR</button>
<button onclick="stop()"id="stop"type="button" name="button">STOP</button>
</div>
<div id="result"></div></div>
<script>
let count = 0;
let counter = setInterval(timer, 500)
function timer(){
count++;
result.innerHTML = count;
}
function desactivar(){
clearInterval(counter)
}
function ReStartFunction(){
clearInterval(counter);
count = 0;
result.innerHTML = count;
counter = setInterval(timer,500);
restart.innerHTML = 'RESTARTED';
}
function pause(){
let onOff = false;
console.log(onOff);
if (!onOff) {
onOff = true;
console.log(onOff);
clearInterval(counter);
document.getElementById('pause').innerHTML = 'REANUDAR';
} else {
onOff = false;
counter = setInterval(timer, 500);
document.getElementById('pause').innerHTML = 'PAUSAR';
}
}
/*var space = false;
body.onkeydown = function(e){
e.preventDefault();
if (e.keyCode == 32 && space == false) {
space = true;
video.pause();
} else {
space = false;
video.play();
}
}*/
</script>
</body>
</head>
</html>