0

I want the countdown timer to pause when I click the pause button, and start from where it left off when I click the go button. It'd also be good if the go button enables again when reset is clicked, but as of now it continues being disabled for as long as the timer was set.

For pausing, I tried what I saw in this fiddle but it didn't work. I also tried this to no avail:

$("#pause").click(function() {
   clearInterval(count()); 
})

Here's the fiddle.

Thanks!

1
  • pause() is not globally defined at jsfiddle Commented Sep 6, 2016 at 9:14

1 Answer 1

1

Here you have solution of working countdown: http://jsfiddle.net/XcvaE/4/

<script>

    var CCOUNT = 60;

    var t, count;

    function cddisplay() {
        // displays time in span
        document.getElementById('timespan').innerHTML = count;
    };

    function countdown() {
        // starts countdown
        cddisplay();
        if (count == 0) {
            // time is up
        } else {
            count--;
            t = setTimeout("countdown()", 1000);
        }
    };

    function cdpause() {
        // pauses countdown
        clearTimeout(t);
    };

    function cdreset() {
        // resets countdown
        cdpause();
        count = CCOUNT;
        cddisplay();
    };

</script>

<body onload="cdreset()">
<span id="timespan"></span>
<input type="button" value="Start" onclick="countdown()">
<input type="button" value="Stop" onclick="cdpause()">
<input type="button" value="Reset" onclick="cdreset()">
</body>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.