From 049c93ae8fb22b3bd66a1b183a8b450b8647781e Mon Sep 17 00:00:00 2001 From: Stephanie Workman Date: Sun, 27 Nov 2016 18:36:12 -0600 Subject: [PATCH] added JS for stopwatch but not fully functional --- style.css | 1 - timers.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/style.css b/style.css index 6ddb643..f25cefb 100644 --- a/style.css +++ b/style.css @@ -27,4 +27,3 @@ button { button:hover{ background: #356094; } - diff --git a/timers.js b/timers.js index fd40910..9d82739 100644 --- a/timers.js +++ b/timers.js @@ -1,4 +1,41 @@ +$ (function(){ + var seconds = 0; + var minutes = 0; + var hours = 0; + var timerId; + function updateTime(){ + seconds++; + if (seconds>59){ + seconds=0; + minutes++; + if (minutes>59){ + minutes=0; + hours++; + } + } + } +$('#start').on('click', function(){ + console.log('start timer'); + var timerId = setInterval(updateTime, 1000); + // document.getElementById('timer').innerHTML = "Time elapsed: "+hours+": "+minutes+": "+seconds; + $('#timer').text("Time elapsed: " + "0" + hours + ":" + "0" + minutes + ":" + seconds + "0"); +}); +$('#pause').on('click', function(){ + console.log('pause timer'); + clearInterval(timerId); +}); + +$('#reset').on('click', function(){ + console.log('reset timer'); + clearInterval(timerId); + seconds=0; + minutes=0; + hours=0; + $('#timer').text("Time elapsed: " + hours + " : " + minutes + ":" + seconds); +}); + +});