Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<p class="neon-text" id="output">00:00:00</p>
<div id="controls">
    <button class="neon-text" id="startPause" onclick="startPause();">START</button>
    <button class="neon-text" onclick="reset();">RESET</button>
</div>
</body>
</html>
 
var time = 0;
var running = 0;
function startPause() {
    if(running === 0){
        running = 1;
        increment();
        document.getElementById('startPause').innerHTML = 'PAUSE';
    }else {
        running = 0;
        document.getElementById('startPause').innerHTML = 'RESUME';
    }
}
function reset() {
    time = 0;
    document.getElementById('startPause').innerHTML = 'START';
    document.getElementById('output').innerHTML = '0:00:00:00';
}
function increment() {
    if (running == 1) {
        setTimeout(function(){
            time++;
            var mins = Math.floor(time/10/60);
            var secs = Math.floor(time/10 % 60);
            var hours = Math.floor(time/10/60/60);
            var tenths = time % 10;
            if (mins < 10) {
                mins = '0' + mins;
            }
            if (secs < 10) {
                secs = '0'+ secs;            
            }
            document.getElementById('output').innerHTML = hours + ':' + mins + ':' + secs+ ':'+tenths+ '0';
            increment();
        }, 100);
    }
}
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers