JavaScript Countdown

StackOverflow #17508108

HTML

<h1>Time Remaining</h1>
    <div id="clock">
        <span id="minutes"></span><span class="separator">:</span><span id="seconds"></span><span class="separator">:</span><span id="centiseconds"></span>
    </div>

CSS

body {
    text-align:center;
}

JavaScript

(function () {

    function Countdown (time) {
        this.minutes        = time.minutes;
        this.seconds        = time.seconds;
        this.centiseconds   = time.centiseconds;
        this.timer          = null;
    }

    Countdown.prototype.start = function () {

        var self = this;

        this.timer = setInterval(function () {
            update();
            decrement();
        }, 10);

        function decrement () {
            self.centiseconds--;
            if (self.centiseconds < 0) {
                self.centiseconds = 99;
                self.seconds--;
                if (self.seconds < 0) {
                    self.seconds = 59;
                    self.minutes--;
                    if (self.minutes < 0) {
                        clearInterval(self.timer);
                    }
                }
            }
        }

        function update () {
            $('#minutes').html(pad(self.minutes));
            $('#seconds').html(pad(self.seconds));
            $('#centiseconds').html(pad(self.centiseconds));

            function pad (number) {
                if (number < 10) {
                    return '0' + number;
                } else {
                    return number;
                }
            }

        };

    };

    return new Countdown({ minutes: 1, seconds: 10, centiseconds: 0 }).start();

}).call();