JSFiddle - React, Tailwind, and code Playground
HTML
<button>Começar</button>
<div id="contador"></div>
CSS
body > * {
padding: 10px;
margin: 10px;
}
JavaScript
function pad(s) {
return (s < 10) ? '0' + s : s;
}
function cronometro(segundos) {
var seg = segundos % 60;
var min = Math.floor(segundos / 60);
document.getElementById('contador').innerHTML = [min, seg].map(pad).join(':');
if (segundos > 0) setTimeout(cronometro, 1000, segundos - 1);
}
document.querySelector('button').addEventListener('click', function() {
cronometro(3 * 60); // 3 x 60 segundos
});