From 878583821f7e1d9bf2101f7d1c5486bd45bcd798 Mon Sep 17 00:00:00 2001 From: Specky Date: Tue, 16 Aug 2022 17:40:18 +0200 Subject: [PATCH] added padNumber --- main.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index 1c33aba..e8eff95 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,7 @@ +function padNumber(number, length) { + return String(number).padStart(length, '0') +} + function compute() { // Initiate basic time variables @@ -19,21 +23,14 @@ function compute() { let frames = (endFrame - startFrame) * frameRate; seconds = Math.floor(frames / frameRate); frames = frames % frameRate; - milliseconds = Math.round(frames / frameRate * 1000); - if (milliseconds < 10) { - milliseconds = '00' + milliseconds; - } else if (milliseconds < 100) { - milliseconds = '0' + milliseconds; - } + milliseconds = padNumber(Math.round(frames / frameRate * 1000), 3); if (seconds >= 60) { minutes = Math.floor(seconds / 60); - seconds = seconds % 60; - seconds = seconds < 10 ? '0' + seconds : seconds; + seconds = padNumber(seconds % 60, 2); } if (minutes >= 60) { hours = Math.floor(minutes / 60); - minutes = minutes % 60; - minutes = minutes < 10 ? '0' + minutes : minutes; + minutes = padNumber(minutes % 60, 2); } // Show the time and mod message in the DOM