Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Countdown clock

jasonnort40jasonnort40 Ft Worth, TXMember Posts: 7

I just finished my countdown clock assignment. I have it set at 15 seconds. When it completes the box says complete...etc...but the box keeps popping up after you close it. How do I fix that? When I remove the return, it stops. Once I close the alert box the timer continues ... which I do not want. Thoughts?

var i;
var minutes = 0;
var seconds = 15;
window.onclick = function() {
countdown('countdown');
}

function countdown() {
    i = setInterval(function() {
        var el = document.getElementById("countdown_clock");
        if(seconds == 0) {
            if(minutes == 0) {
                alert(el.innerHTML = "Hot Dog It Actually Worked!");                    
                clearInterval(i);
                return;
            } else {
                minutes--;
                seconds = 60;
            }
        }
        if(minutes > 0) {
            var minute_text = minutes + (minutes > 1 ? ' minutes' : ' minute');
        } else {
            var minute_text = '';
        }
        var second_text = seconds > 0 ? 'seconds' : 'second';
        el.innerHTML = minute_text + ' ' + seconds + ' ' + second_text + ' remaining';
        seconds--;
    }, 1000);
}
Tagged:
Sign In or Register to comment.