From 1eb9e6651b223d3515d42bdd66b821f92fd32638 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Tue, 30 Jun 2020 14:48:00 -0400 Subject: [PATCH] format time --- app.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 52bfdba..1e5c063 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,17 @@ let startTime; let windowInterval; +const formatTime = (total) => { + const hours = Math.floor(total/60/60); + const minutes = Math.floor( (total - (hours*60*60)) / 60 ); + const seconds = total - minutes*60 - hours * 60 * 60; + return `${hours}:${minutes}:${seconds}`; +} + const displayTime = () => { // console.log(Date.now()-startTime); - document.querySelector('h1').innerHTML = Math.floor((Date.now()-startTime)/1000); + const timeString = formatTime(Math.floor((Date.now()-startTime)/1000)); + document.querySelector('h1').innerHTML = timeString; } document.querySelector('.btn-primary').addEventListener('click', (event) => { @@ -15,6 +23,6 @@ document.querySelector('.btn-secondary').addEventListener('click', (event) => { window.clearInterval(windowInterval) }) -window.onbeforeunload = function(){ - return 'Good bye' -} +// window.onbeforeunload = function(){ +// return 'Good bye'; +// }