I have three javascript functions:
function updateTest() {
if (totalmin == "0") {
coolvar = "start";
} else {
coolvar = "stop";
}
}
setInterval(updateTest, 1000)
var audvar = setInterval(function () {
cooltrigger()
}, 60000);
function cooltrigger() {
updateaudio(coolvar);
}
I need to design another function that checks the state of coolvar for the same interval, but updates html code the once upon coolvar=start. It then should hold and not update this variable for 60 seconds and then returns to the previous state.
function updateaudio(coolvar) {
var a_str;
if (coolvar == "start") {
a_str = '<audio autoplay source src="audio/coolsound.mp3" type="audio/mpeg"></audio>';
}
if (coolvar == "stop") {
a_str = '<!--Coolsound will only go off at 0:00 timer -->';
}
document.getElementById('audio_span').innerHTML = a_str;
}
//setTimeout(updateaudio, 6000);
At the moment using the current code, coolvar will be checked once every 60 seconds then update a_str. I wanted to check coolvar every second but update a_str only once upon first triggering updateaudio.
What am I doing wrong? Is there another way to achieve this?