window.onload = function(){
function timer(){
let minute = document.getElementById('minute').innerHTML;
let second = document.getElementById('second').innerHTML;
let end = false;
if( second > 0 ) {
second--;
if( second < 10){
'0'+second;
}
} else{
second = 60;
if( minute > 0 ) {
minute--;
if(minute < 10){
'0'+minute
}
} else{
end = true;
}
}
if(end){
clearInterval(intervalID);
alert("Время истекло!");
}else{document.getElementById('minute').innerHTML = minute;
document.getElementById('second').innerHTML = second;
}
}
window.intervalID = setInterval(timer, 1000);
}
<div id='timer'>
<div id='minute'>01</div>:
<div id='second'>10</div>
</div>
function pad(x) {
return x < 10 ? '0' + x : x;
}
document.getElementById('minute').innerHTML = pad(minute);
document.getElementById('second').innerHTML = pad(second);
window.onload = function(){
function timer(){
let minute = document.getElementById('minute').innerHTML;
let second = document.getElementById('second').innerHTML;
let end = false;
if( second > 0 ) {
second--;
if( second < 10) {
second = '0'+second
};
} else{
second = 60;
if( minute > 0 ) {
minute--;
if(minute < 10){
minute = '0'+minute
}
} else{
end = true;
}
}
if(end){
clearInterval(intervalID);
alert("Время истекло!");
}else{document.getElementById('minute').innerHTML = minute;
document.getElementById('second').innerHTML = second;
}
}
window.intervalID = setInterval(timer, 1000);
}