Skip to content

Instantly share code, notes, and snippets.

@dmc2015
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmc2015/aa69998be52cf7c0c478 to your computer and use it in GitHub Desktop.
Save dmc2015/aa69998be52cf7c0c478 to your computer and use it in GitHub Desktop.
stopclock with moment - JS
var startButton = document.getElementById("start")
var resetButton = document.getElementById("reset")
var pauseButton = document.getElementById("pause")
var textBox = document.getElementById("timer")
var time = 0
var intervalID
startButton.addEventListener("click", function(event){
event.preventDefault();
intervalID = setInterval(function(){//could i change function to an actual function and then call the below text?
time++;
var stringTime = time.toString();
var timeFormated = (moment(stringTime).startOf('second').format('HH:mm:ss'))
textBox.innerHTML = "Time elapsed: " + (timeFormated);
}, 1000); 
})
resetButton.addEventListener("click", function(event){
textBox.innerHTML = ("Stop Watch");
time = 0 ;
clearInterval(intervalID)
})
pauseButton.addEventListener("click", function(event){
var pauseTimer = clearInterval(intervalID)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment