Reputation: 91
I have two window intervals that set a text and then remove a text, but after the first time they go, it sets them off balance. How can I make timer 1, start timer 2 after it finishes?
Timer 1:
window.setInterval(function(){
save();
document.getElementById('autosave').innerHTML = 'Game Saved';
}, 30000);
Timer 2:
window.setInterval(function(){
document.getElementById('autosave').innerHTML = '';
}, 2000);
Upvotes: 1
Views: 116
Reputation: 6228
You don't need 2 intervals, you can just make your first interval start a setTimeout
in which you remove the text after some time.
window.setInterval(function(){
save();
document.getElementById('autosave').innerHTML = 'Game Saved';
setTimeout(function(){
document.getElementById('autosave').innerHTML = '';
}, 2000);
}, 30000);
Upvotes: 1
Reputation: 6904
setInterval(function(){
save();
document.getElementById('autosave').innerHTML = 'Game Saved';
setTimeout(function(){
document.getElementById('autosave').innerHTML = '';
}, 2000);
}, 30000);
Upvotes: 1