diff --git a/readme.md b/readme.md index 902f652..cc2b58d 100644 --- a/readme.md +++ b/readme.md @@ -10,9 +10,19 @@ We've been tasked with building out the behavior for a digital stopwatch, the in ####Directions Spend 10 minutes looking at [JavaScript Timers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers), then check out the specific documentation for `setInterval` and `clearInterval`. +setImmediate() + Calls a function immediately after the browser has completed other operations, such as events and display updates. +clearTimeout() + Clears the delay set by setTimeout(). +clearInterval() + Cancels repeated action which was set up using setInterval(). +clearImmediate() + Cancels the immediate actions, just like clearTimeout() for setTimeout(). + + ####Take It Step By Step -This is a tough assignment, so don't stress over meeting all the requirements. Just take it step by step and try to meet the benchmarks below in order. +This is a tough assignment, so don't stress over meeting all the requirements. Just take it step by step and try to meet the benchmarks below in order. 1. Create Javascript selectors that target each of the timer buttons. 2. Create click handlers (empty, for now) for each of the timer buttons. diff --git a/timers.js b/timers.js index fd40910..077a068 100644 --- a/timers.js +++ b/timers.js @@ -1,4 +1,40 @@ +$(document).ready(function(){ + let reset = $(".controls").find("#reset"); + let start = $(".controls").find("#start"); + let pause = $(".controls").find("#pause"); +console.log(reset, start, pause); +///set the variables + let seconds = 0; + let timerId = 0; + let timer; +///set the click events and what happens inside them +//reset button +$(reset).on('click', function(){ + console.log("reset"); + clearInterval(timer); + seconds = 0; + $('#timer').html(seconds); +}); +//start buttom +$(start).on('click', function(){ + console.log("start"); + timer = window.setInterval(updateTime, 1000); + console.log(seconds) +}); +//pause button +$(pause).on('click', function(){ + console.log("pause"); + clearInterval(timer); +}); + +//update time function +updateTime = function(){ + $('#timer').html(seconds); + seconds = seconds+1; +}; + +});////END OF DOCUMENT READY