Last active
August 29, 2015 14:20
-
-
Save dmc2015/aa69998be52cf7c0c478 to your computer and use it in GitHub Desktop.
stopclock with moment - JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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