JSFiddle - React, Tailwind, and code Playground

by Ravindra Athreya

HTML

<h1>Enter minutes you want to work </h1>
<input id="request" type="text" placeholder="Enter an amount here">
<a href="#" class="click">Click here</a>

JavaScript

$('.click').click(function () {
    var rawAmount = $('#request').val();
    var cleanAmount = rawAmount.split(':');
    var totalAmount = parseInt(cleanAmount[0] | 0) * 60 + parseInt(cleanAmount[1] | 0);
     $('#request').val(" ");

    var loop, theFunction = function () {

        totalAmount--;

        if (totalAmount == 0) {

            clearInterval(loop);
        }
        var minutes = parseInt(totalAmount/60);
        var seconds = parseInt(totalAmount%60);

        if(seconds < 10)
            seconds = "0"+seconds;
        $('#request').val(minutes + ":" + seconds);
    };

    var loop  = setInterval(theFunction, 1000);

})