I made a one minute countdown timer in JavaScript. it works properly and announces result when I am on The timer tab. The problem is when the timer starts and i switch to another tab and come back to the timer tab, its counting time correctly but once it reaches 00:00 it starts counting as 59:58. it does not announce result. what's wrong with the code?
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "free_dance_response.php", false);
xmlhttp.send(null);
if (xmlhttp.responseText == "Time Out") {
myStopFunction();
//quitWarning_timer();
}
$('#response1').html(xmlhttp.responseText);
}
function myStopFunction() {
clearInterval(myVar);
}