Count Down

counting down a number

by s_light

HTML

<div id="remainingTime">10</div>
<div onClick="restart()">restart</div>

JavaScript

function nextSecondCountDown() {
    
    var remainingTime = 0;
    remainingTime = document.getElementById("remainingTime").firstChild.nodeValue ;
    //console.log(remainingTime);
    if ( remainingTime > 0 ) {
        remainingTime = remainingTime - 1;
        document.getElementById("remainingTime").firstChild.nodeValue = remainingTime;
        window.setTimeout("nextSecondCountDown()", 1000);
    } else {
        document.getElementById("remainingTime").firstChild.nodeValue = "pleas reload page!";
    }
}

function restart(){
    document.getElementById("remainingTime").firstChild.nodeValue = 10;
    nextSecondCountDown();
}