0

Currently I am using the code below to express a time in seconds (900) in seconds and minutes (15 mins 0 Seconds).

I am wondering if there is an easier way to achieve this as trying to use the same method fails for the first timer.

function cddisplay() {
    // displays time in span
    document.getElementById('timespan').innerHTML = Math.floor(count / 60) + ":" + count % 60;
    if (scount % 60 >= 10) {
        document.getElementById('timespan1').innerHTML = Math.floor(scount / 60) + ":" + scount % 60;
    } else {
        document.getElementById('timespan1').innerHTML = Math.floor(scount / 60) + ":0" + scount % 60;
    }
};
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Keir Liddle
  • 111
  • 3
  • Please explain a little more. Its unclear when its not working. – Maheer Ali Jan 07 '20 at 16:59
  • 1
    Does this answer your question? [Javascript seconds to minutes and seconds](https://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes-and-seconds) – Ryan Sparks Jan 07 '20 at 17:00
  • 1
    Unrelated, but it might be easier to read overall if you pulled out all the repeated math and DOM lookups. – Dave Newton Jan 07 '20 at 17:01
  • 1
    https://stackoverflow.com/questions/2998784/how-to-output-numbers-with-leading-zeros-in-javascript – str Jan 07 '20 at 17:02
  • perhaps a typo in your code? you have a `scount` that's not defined anywhere – Nam Kim Jan 07 '20 at 17:42

0 Answers0