3
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by slametcahboyolali
0

Not Tested:

var timer = {

    // ID of div to display the time
    divId: "myDivId",

    // Used to store the div object
    div: undefined,

    // Used to store the interval object
    interval: undefined,

    // Used to store the current time
    currentTime: 0,

    // Initialize timer
    init : function() {

        timer.div = document.getElementById(timer.divId);

        timer.interval = setInterval(function() {

            timer.currentTime = currentTime + 1;

            timer.updateTimeDisplay();

        }, 1000); // 1000 milliseconds = 1 second
    },

    updateTimeDisplay: function() {
        timer.div.innerHTML = timer.currentTime + " seconds";
    },

    stop: function() {
        clearInterval(timer.interval);
    }

};

// Initialize timer
timer.init();


// Stop timer after 100000 milliseconds
setTimeout(function() {

    timer.stop();

}, 100000);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.