Created
November 12, 2015 07:01
-
-
Save jalehman/d91604fdd2495c4649de to your computer and use it in GitHub Desktop.
This file contains hidden or 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 makeStopwatch = function() { | |
var elapsed = 0; | |
var intervalId; | |
var increase = function() { elapsed++; }; | |
var stopInterval = function() { | |
clearInterval(intervalId); | |
}; | |
return { | |
start: function() { intervalId = setInterval(increase, 1000); }, | |
view: function() { return elapsed; }, | |
pause: stopInterval, | |
reset: function() { | |
elapsed = 0; | |
stopInterval(); | |
return "I'm reset!"; | |
} | |
}; | |
}; | |
var myStopwatch = makeStopwatch(); | |
myStopwatch.start(); | |
myStopwatch.stop(); | |
myStopwatch.reset(); | |
myStopwatch.view(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment