I created a countdown timer that displays a div when the timer reaches zero. However, I am struggling with getting the timer to reset and start counting down again after displaying the div.
For instance, if I set the timer for 7 days and it reaches the deadline, the div should be displayed for 7 days before starting the countdown again for another 7 days.
I can easily implement a basic timer that shows the div when time is up, but I'm unsure how to make it count down again and display the div repeatedly without resetting upon refresh.
Here is my code snippet:
var time = 5;
window.setInterval(test, 1000);
function test() {
time -= 1;
$('#test').html(time);
if (time == 0) {
$('#test').remove();
$('#a').show();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="test" style="border:1px solid black;width:100px">test
</div>
<div id="a" style="display:none;">
testing
</div>