I want to pause timer when the value in the answer box is 119.
I'm not able to pause the timer or clearInterval when the value is 119, the timer won't pause.
<body onload="document.getElementById('box1').focus, startTimer(), pause()">
<input onkeyup="sum(),secret()" id="box1" autofocus/><br><br>
<input onkeyup="sum(),secret()" id="box2"/><br><br>
<input id="ans" disabled/>
<p id="secret" style="display: none;">
Time paused
</p>
<script>
function secret() {
if(document.getElementById('ans').value == "119") {
document.getElementById('secret').style.display = "block";
}
else {
document.getElementById('secret').style.display = "none";
}
}
function sum() {
var x = document.getElementById('box1').value;
var y = document.getElementById('box2').value;
var a = +x + +y;
document.getElementById('ans').value = a;
}
function startTimer() {
var fiveMinutes = 30,
display = document.getElementById("time"),
mins, seconds;
var tt = setInterval(function() {
mins = parseInt(fiveMinutes / 60)
seconds = parseInt(fiveMinutes % 60);
seconds = seconds < 10 ? "0" + seconds : seconds;
display.innerHTML = mins + ":" + seconds;
fiveMinutes--;
if (fiveMinutes < 0) {
document.getElementById('timeup').style.display = "block";
clearInterval(tt);
}
}, 1000);
}
function pause() {
setInterval(pau, 10);
}
function pau() {
if(document.getElementById('secret').style.display == "block") {
}
}
</script>
<br>
<br>
<div onchange="pause()" id="time"></div>
<p id="timeup" style="display: none;">Time up </p>
</body>