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 2 of 2

Thread: stopwatch

  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation stopwatch

    if i try to make a stop watch with this simple code:

    Code:
    var seconds = 0
    var minutes = 0
    function custom(){
    if (seconds<60){
     minutes = minutes
     seconds = parseFloat(seconds)+parseFloat(1)
     }
    else if (seconds==59){
     minutes = parseFloat(minutes)+parseFloat(1)
     seconds = 0
     }
    if (seconds<10){
     seconds = "0"+seconds
     }
    document.byu.cougar.value = minutes+":"+seconds
    setTimeout("custom()",1000)
    }
    then how can i make the STOPwatch STOP?!?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,986
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Presumably you need to stop, start and reset. This should do the trick.

    http://javascript.internet.com/misce...stopwatch.html


    If you want seconds rather than milliseconds change the three instances of
    document.stpw.time.value = ms;
    to
    document.stpw.time.value = ms/1000;

    or if you want to show whole seconds only
    document.stpw.time.value = Math.round(ms/1000);
    Last edited by Philip M; 05-03-2006 at 07:45 AM.


  •  

    Posting Permissions

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