From 780585e0a7501275b19e998d9a40f33a6a9b2b9e Mon Sep 17 00:00:00 2001 From: awanderlyss Date: Sun, 27 Nov 2016 19:45:01 -0500 Subject: [PATCH] Add start, reset, pause functions to buttons --- index.html | 2 +- timers.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index c1129f7..bde82ed 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ i ♥ js - + diff --git a/timers.js b/timers.js index fd40910..4728837 100644 --- a/timers.js +++ b/timers.js @@ -1,4 +1,32 @@ +// reset button +const reset = $('#reset'); +// start button +const start = $('#start'); +// pause button +const pause = $('#pause'); +const timer = $('#timer'); +var seconds = 0; +var timerId = 0; +reset.on("click", function () { + clearInterval(timerId); + seconds = 0; + timer.text('Stop Watch'); +}); + +start.on("click", function () { + timer.text(`Time elapsed: ${seconds}`); + timerId = setInterval(updateTime, 1000); +}); + +pause.on("click", function (){ + clearInterval(timerId); +}); + +function updateTime () { + seconds++; + timer.text(`Time elapsed: ${seconds}`); +}