Nate Rice
Nate Rice

Reputation: 91

make a interval start another interval

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

Answers (2)

Alexandru Severin
Alexandru Severin

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

MoeSattler
MoeSattler

Reputation: 6904

setInterval(function(){
    save();
    document.getElementById('autosave').innerHTML = 'Game Saved';
    setTimeout(function(){
        document.getElementById('autosave').innerHTML = '';
    }, 2000);
}, 30000);

Upvotes: 1

Related Questions