Created
October 15, 2016 09:35
-
-
Save joepegler/b401ad943847ac65d23183a6f55fa8a3 to your computer and use it in GitHub Desktop.
Simple start/stop Javascript timer
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 Timer = (function Timer() { | |
var vars = { | |
startTime: 0, | |
stopTime: 0, | |
time: 0, | |
reset: function() { | |
vars.startTime = 0; | |
vars.stopTime = 0; | |
vars.time = 0; | |
} | |
} | |
return function() { | |
var _this = this; | |
_this.start = function() { | |
vars.reset(); | |
vars.startTime = new Date().getTime(); | |
}; | |
_this.stop = function() { | |
vars.stopTime = new Date().getTime(); | |
vars.time = Math.round((vars.stopTime - vars.startTime) / 10); | |
return vars.time; | |
}; | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment