From 2c46d60218ee3c94e8f49a6ff9bd21e7f57f2877 Mon Sep 17 00:00:00 2001 From: yourUsername Date: Sun, 27 Nov 2016 18:20:24 -0500 Subject: [PATCH] DaraHoy Week02 Day02 HW --- timers.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/timers.js b/timers.js index fd40910..1a54873 100644 --- a/timers.js +++ b/timers.js @@ -1,4 +1,32 @@ +//selectors for stopwatch buttons +let $reset = $("#reset"); +let $start = $("#start"); +let $pause = $("#pause"); +let $timer = $("#timer"); +//declare variables for seconds and timerID +let seconds = 0; +let timerID = 0; +//create update timer function +let updateTimer = function(){ + timerID = setInterval(updateSeconds, 1000); +}; +//increments the seconds +let updateSeconds = function(){ + seconds++; + console.log(seconds); + $timer.html(seconds); +}; +let pauseTime = function(){ + clearInterval(timerID); +}; +let resetTime = function(){ + clearInterval(timerID); + seconds = 0; + $timer.html("Stop Watch"); +}; - - +$reset.on("click", resetTime); +$start.on("click", updateTimer); +$pause.on("click", pauseTime); +//Bug with clicking start multiple times starts a new start ID