JSFiddle - React, Tailwind, and code Playground

by brunolm

HTML

<div id="c"></div>

JavaScript

var $c = $("#c");
var template = "{0} minutes {1} seconds";

var format = function(z){var a=arguments;return z.replace(/(\{\{\d\}\}|\{\d\})/g,function(m){if(m.substring(0,2)=="{{")return m;var n=parseInt(m.match(/\d/)[0]);return a[n+1]})};

$c.data("StartTime", 10 * 60);
var interval = setInterval(function() {
    var time = $c.data("StartTime");
    $c.data("StartTime", --time);

    var d = new Date(time * 1000);    
    
    // use d.getMinutes and d.getSeconds()
    // to change the class name
    // you can use a switch

    $c.html(format(template, d.getMinutes(), d.getSeconds()));
    
    if (time <= 0) clearInterval(interval);
}, 1000);