0

<script>

var mins = 0.10;

var secs = mins * 60;
function countdown() {
    setTimeout('Decrement()',1000);
}
function Decrement() {
    if (document.getElementById) {
        minutes = document.getElementById("minutes");
        seconds = document.getElementById("seconds");
        // if less than a minute remaining

        if (seconds < 59) {
            seconds.value = secs;

        } else {
            minutes.value = getminutes();
            seconds.value = getseconds();
        }
        secs--;
        setTimeout('Decrement()',1000);

        if (secs == 0) 
        {
         alert('time up !!! You must submit your Answer ');       
         }

    }
}   
function getminutes() {
    // minutes is seconds divided by 60, rounded down
    mins = Math.floor(secs / 60);
    return mins;

}
function getseconds() {
    // take mins remaining (as seconds) away from total seconds remaining
    return secs-Math.round(mins *60);
}

</script>
2
Contributors
4
Replies
23
Views
3 Years
Discussion Span
Last Post by infoitmanoj
1

You could add a counter that counts how many times the function has been executed. If it reaches 10, you could prevent the timeout from being set again. I hope that's clear enough :).

1

Your script should include something like this:

var number_of_timeouts_executed = 0;

// (Your decrement function:)
function decrement() {

    // If 10 or more timeouts have already been excuted, it's been 10 seconds or more. 
    // Don't execute this function again.
    if(number_of_timeouts_executed >= 10)
        return false;

    number_of_timeouts_executed++;

    // (Your timeout:)
    setTimeout();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.