Last active
June 6, 2017 19:14
-
-
Save iamwill123/067bfc99d2c8904583da59ba68ba7ce0 to your computer and use it in GitHub Desktop.
StopWatch created by iamwill123 - https://repl.it/I9AY/0
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
// 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