Skip to content

Instantly share code, notes, and snippets.

@iamwill123
Last active June 6, 2017 19:14
Show Gist options
  • Save iamwill123/067bfc99d2c8904583da59ba68ba7ce0 to your computer and use it in GitHub Desktop.
Save iamwill123/067bfc99d2c8904583da59ba68ba7ce0 to your computer and use it in GitHub Desktop.
StopWatch created by iamwill123 - https://repl.it/I9AY/0
// create a stop watch
function makeStopWatch() {
var seconds = 0;
var intervalID;
function tickTock() {
console.log(seconds);
return seconds++;
}
function startWatch() {
// function to start our watch
console.log(intervalID);
intervalID = setInterval(tickTock, 1000);
}
function stopWatch() {
// function to stop our watch
clearInterval(intervalID);
}
return {
start: startWatch,
stop: stopWatch
}
}
var appleWatch = makeStopWatch();
appleWatch.start(); // fire it off
setTimeout(function() {
appleWatch.stop();
}, 9000); // stop after 8 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment