Game to guess how long

[Total: 0    Average: 0/5]

The guess time is 5 seconds, how close can you get?

Head Code:

<script>
var RESOLUTION=50; /* 50 msecs */
var GUESSTIME=5*1000; /* 5 seconds */
var myTimer=null;
var timeCount=0;
function stopIt()
{
  if(myTimer)
  {
    clearInterval(myTimer);
    myTimer=null;
  }
  timeCount=0;
}
function startIt()
{
   stopIt();
   myTimer=setInterval("tictoc()",RESOLUTION);
}
function tictoc()
{
  timeCount+=RESOLUTION;
  if(timeCount>=GUESSTIME)
  {
    stopIt();
    alert("You waited too long.");
  }
}
function guessNow()
{
  var timeCounted=timeCount;
  stopIt();
  if(timeCounted==0)
  {
    alert("You did not start it yet.");
  }
  else
  {
    var wait=parseFloat(timeCounted)/1000.0;
    alert("You waited "+wait+" seconds.");
  }
}
</script>

Body Code:

Click start and see if you can wait 5 seconds with out going over.
<BR>
<form>
<input type=button value="Start" onclick="startIt()">
<input type=button value="Guess" onclick="guessNow()">
</form>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *