From 164b372e7f9162cb3c81a410b4bf0cad97521019 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Tue, 30 Jun 2020 16:53:28 -0400 Subject: [PATCH] pad digits --- app.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 1e5c063..858ff28 100644 --- a/app.js +++ b/app.js @@ -1,11 +1,19 @@ let startTime; let windowInterval; +const padDigits = (value) => { + if(value < 10){ + return '0'+value; + } else { + return value; + } +} + 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}`; + return `${padDigits(hours)}:${padDigits(minutes)}:${padDigits(seconds)}`; } const displayTime = () => {