Skip to content

TheNew000/countdownTimer

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

#Countdown Timer using JavaScript

This is a basic timer that uses setInterval to countdown from the present moment to the desired time. What I loved about this app was manipulating the interval of time. Basing it off of some characters from the cartoon, Rick & Morty, you can either Slow Down Time:

function slowMoWrapper(clock){
        clearInterval(time);
        if(clock === clock1){
            now = (rioStart - Date.now()) / 1000;
        }else{
            now = (deathStart - Date.now()) / 1000;
        }
        slowMo = setInterval(
        function(){
            getNewTime('slomo', clock);
            updateCounter(clock);
        }, 3000);
};

As you can see, with the setInterval function, I set the new interval to decrement each second every three seconds instead of 1:1

Stopping time was surpisingly easy! All I had to do was ad a onclick="clearInterval(slowMo); clearInterval(time);" to the button's html essentially stopping time whether it was slowed down or just ticking away at a normal interval.

Getting the time to start again was also dealt with in a simple manner:

function timeWrapper(){
    clearInterval(slowMo);
    time = setInterval(
    function(){
        getNewTime('reg', clock1);
        updateCounter(clock1);
        getNewTime('reg2', clock2);
        updateCounter(clock2);
    }, 1000);
}

This is the same function that starts the timer when you originally load the page! I added the clearInterval(slowMo); to clear the slower interval as it seemed to continue to impact regular time and made the countdown clock jumpy.

Live Demo @ http://www.dannyarango.com/countdownTimer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published