Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: turn counters.

  1. #1
    New Coder
    Join Date
    Sep 2010
    Location
    High Wycombe, UK
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    turn counters.

    I want to write a count down timer (done!).
    That counts downwards every second (done!).
    That auto-resets every time it reaches 0 (done!).
    But every time it does that I want an upcounter to count up from zero (not done!).

    Best I can do is:
    Code:
    function startCountdown(){
           if(Count >= 2){
                Count = Count - 1;
                numberCountdown.innerText = "Your turn ends in " + Count + " seconds";
                setTimeout('startCountdown()',1000);
           }
    	   else {
    	   Count = 11;
    	   //Rounds = Rounds + 1;
    	   //document.write("This is round " + Rounds + "</p>");
    	   startCountdown();
    	   }
    	   
    }
    also i find i can click that button multiple times which i need to somehow disable. Please help.

    Thanks,
    Morlaf
    Morlaf - Learning JavaScript!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    Remove the else portion. Have the button pass in 11 as a parameter. First thing in function is disable button. Write new else to count up.
    Evolution - The non-random survival of random variants.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,732
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Code:
    <div id = "time"></div>
    
    <script type = "text/javascript">
    
    var secs;
    function displaydown(secs) {
    if (secs <= 0) { 
    alert("Your time is up!");
    displayup(0);
    }
    else {
    secs--;
    document.getElementById("time").innerHTML = secs
    setTimeout("displaydown("+secs+")",1000);
    }
    }
    
    function displayup(secs) {
    secs++;
    document.getElementById("time").innerHTML = secs
    setTimeout("displayup("+secs+")",1000);
    }
    
    
    displaydown(31); // add one second to start countdown at e.g. 30 secs = 31
    
    </script>
    What button? But you can easily disable a button in your Javascript code with

    document.getElementById("mybutton").disabled = true;


    Quizmaster: In computing terms, what does the acronym RAM stand for?
    Contestant: Red and Maroon

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    Morlaf (05-31-2013)

  • #4
    New Coder
    Join Date
    Sep 2010
    Location
    High Wycombe, UK
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    <div id = "time"></div>
    
    <script type = "text/javascript">
    
    var secs;
    function displaydown(secs) {
    if (secs <= 0) { 
    alert("Your time is up!");
    displayup(0);
    }
    else {
    secs--;
    document.getElementById("time").innerHTML = secs
    setTimeout("displaydown("+secs+")",1000);
    }
    }
    
    function displayup(secs) {
    secs++;
    document.getElementById("time").innerHTML = secs
    setTimeout("displayup("+secs+")",1000);
    }
    
    
    displaydown(31); // add one second to start countdown at e.g. 30 secs = 31
    
    </script>
    What button? But you can easily disable a button in your Javascript code with

    document.getElementById("mybutton").disabled = true;


    Quizmaster: In computing terms, what does the acronym RAM stand for?
    Contestant: Red and Maroon

    This code does not do what i want - bu that is good; it means i can tweak and fiddle and get it to do what i want. so I'm spoon-feb but at least you aint chewing my food for me too!

    Thanks again guys!
    Morlaf - Learning JavaScript!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •