jasonlong/mater

Add basic countdown timer

jasonlong opened this issue · 2 comments

Find a npm module for handling the countdown. Hardcoding 25 minutes is fine for now.

let countdownTimer = (minutes, renderCountdown, timeout) => {
    'use strict'

    let secondInJavaScript = 1000
    let secondsInOneMinute = 60
    var countdown = minutes * secondsInOneMinute

    renderCountdown(countdown)

    let timer = setInterval(() => {
        countdown -= 1

        if (countdown === 0) {
            clearInterval(timer)
            timeout()
        } else {
            renderCountdown(countdown)
        }
    }, secondInJavaScript)
}

countdownTimer(1, console.log, () => { console.log('timeout') })

/*
 * P.S. You're welcome.
 */

Thanks @BekoBou. I have a PR for this over at #4 that uses a nice package for the timing bits.