Skip to content

Instantly share code, notes, and snippets.

@jalehman
Created October 15, 2015 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jalehman/0e70cfe0c35794e20772 to your computer and use it in GitHub Desktop.
Save jalehman/0e70cfe0c35794e20772 to your computer and use it in GitHub Desktop.
var makeStopwatch = function() {
var elapsed = 0;
var interval;
var stopwatch = function(){
return elapsed;
};
var increase = function() { elapsed++; };
return {
start: function() { interval = setInterval(increase, 1000); },
view: function() { return elapsed; },
reset: function() { elapsed = 0; return "I'm reset!"; },
stop: function() { clearTimeout(interval); }
};
};
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