From d46242a438485af43a42d7bf085b6d9d78c0349c Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 29 Jun 2020 17:02:47 -0400 Subject: [PATCH] basics --- app.js | 20 ++++++++++++++++++++ index.html | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index e69de29..52bfdba 100644 --- a/app.js +++ b/app.js @@ -0,0 +1,20 @@ +let startTime; +let windowInterval; + +const displayTime = () => { + // console.log(Date.now()-startTime); + document.querySelector('h1').innerHTML = Math.floor((Date.now()-startTime)/1000); +} + +document.querySelector('.btn-primary').addEventListener('click', (event) => { + startTime=Date.now(); + windowInterval = window.setInterval(displayTime,1000) +}) + +document.querySelector('.btn-secondary').addEventListener('click', (event) => { + window.clearInterval(windowInterval) +}) + +window.onbeforeunload = function(){ + return 'Good bye' +} diff --git a/index.html b/index.html index 7c5c2b4..3c943bc 100644 --- a/index.html +++ b/index.html @@ -7,14 +7,14 @@ - - Hello, world! + Practice Timer
-

Hello, world!

+

+