Results 1 to 2 of 2
  1. #1
    saintwolfe is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default Simple Timer with Intervals

    Hey guys I am a student in college currently taking an intro to computer science class. I have taken a liking to it and have decided to try and learn some coding. Currently I am working on a timer basically one from online, that I want to fix up. I'll post script below for advice, anyways my goal is to create intervals on the timer so that it will have two screens, overall time and rounds time. Therefore I want to implement intervals into it so that its on a loop pattern going 30seconds, 10seconds, 30seconds until it hits 10minutes or whatever. Any advice tips or help would be much appreciated. In my class currently we are just doing html so this is all new to me.


    <script language="javascript">
    var base = 60;

    var clocktimer,dateObj,dh,dm,ds,ms;
    var readout='';
    var h=1;
    var m=1;
    var tm=1;
    var s=0;
    var ts=0;
    var ms=0;
    var show=true;
    var init=0;
    var mPLUS=new Array(
    'm0',
    'm1',
    'm2',
    'm3',
    'm4',
    'm5',
    'm6',
    'm7',
    'm8',
    'm9'
    );
    var ii=0;

    function clearALL() {
    clearTimeout(clocktimer);
    h=1;m=1;tm=1;s=0;ts=0;ms=0;
    init=0;show=true;
    readout='00:00:00.00';
    document.clockform.clock.value=readout;
    var CF = document.clockform;
    for (ij=0;ij<=9;ij++) { CF[mPLUS[ij]].value = ''; }
    ii = 0;
    }

    function addMEM() {
    if (init>0) {
    var CF = document.clockform;
    CF[mPLUS[ii]].value = readout;
    if (ii==9) { ii = 0; } else { ii++; }
    }
    }


    function startTIME() {

    var cdateObj = new Date();
    var t = (cdateObj.getTime() - dateObj.getTime())-(s*1000);

    if (t>999) { s++; }

    if (s>=(m*base)) {
    ts=0;
    m++;
    } else {
    ts=parseInt((ms/100)+s);
    if(ts>=base) { ts=ts-((m-1)*base); }
    }

    if (m>(h*base)) {
    tm=1;
    h++;
    } else {
    tm=parseInt((ms/100)+m);
    if(tm>=base) { tm=tm-((h-1)*base); }
    }

    ms = Math.round(t/10);
    if (ms>99) {ms=0;}
    if (ms==0) {ms='00';}
    if (ms>0&&ms<=9) { ms = '0'+ms; }

    if (ts>0) { ds = ts; if (ts<10) { ds = '0'+ts; }} else { ds = '00'; }
    dm=tm-1;
    if (dm>0) { if (dm<10) { dm = '0'+dm; }} else { dm = '00'; }
    dh=h-1;
    if (dh>0) { if (dh<10) { dh = '0'+dh; }} else { dh = '00'; }

    readout = dh + ':' + dm + ':' + ds + '.' + ms;
    if (show==true) { document.clockform.clock.value = readout; }

    clocktimer = setTimeout("startTIME()",1);
    }

    function findTIME() {
    if (init==0) {
    dateObj = new Date();
    startTIME();
    init=1;
    } else {
    if(show==true) {
    show=false;
    } else {
    show=true;
    }
    }
    }
    </script>
    <form name="clockform">
    <input name="clock" style="text-align:center; width:174px; height:35px; font-size:24; font-weight:bold" value="00:00:00.00" /> <input name="starter" onclick="findTIME()" style="width:97px; font-weight:bold" type="button" value="Start/Stop" /> <input name="clearer" onclick="clearALL()" type="button" value="Reset" />&nbsp;</form>
    <hr />
    <h2>

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,237
    Rep Power
    19

    Default Re: Simple Timer with Intervals

    This is a Java forum. JavaScript is not Java. Find a JavaScript forum for your question.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Intervals of Days and Weeks
    By jazob in forum New To Java
    Replies: 0
    Last Post: 12-14-2011, 10:55 PM
  2. Trying to create simple Timer, doesn't work
    By Ragoune in forum New To Java
    Replies: 4
    Last Post: 07-06-2011, 09:24 PM
  3. How do you create a simple timer?
    By Arnold in forum New To Java
    Replies: 2
    Last Post: 11-01-2009, 04:53 PM
  4. how to change password in regular intervals
    By mohan404 in forum Advanced Java
    Replies: 4
    Last Post: 04-08-2008, 11:46 AM
  5. Simple timer
    By im-not-alive in forum New To Java
    Replies: 1
    Last Post: 01-20-2008, 09:04 PM

Posting Permissions

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