Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jalehman
Created November 12, 2015 07:01
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 jalehman/d91604fdd2495c4649de to your computer and use it in GitHub Desktop.
Save jalehman/d91604fdd2495c4649de to your computer and use it in GitHub Desktop.
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