we an easily make a stopwatch in javascript. I have used two functions in making of javascript stopwatch by use of two functions namely timedCount() and stopCount() as they have been described in the code below.
we can make both incrementing and decrementing stop watch in javascript using the code below by making very few changes. we can change the starting value by making changes in variable c value accordingly.
///////////////////////////////////
Here is the code for incrementing:
//////////////////////////////////
<html>
<head>
<title>stopwatch</title>
</head>
<script type="text/javascript">
var c=0
var t
function stopCount()
{
clearTimeout(t)
}
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
if(c==61)
{
alert("time over")
stopcount()
}
t=setTimeout("timedCount()",1000)
}
</script>
<body>
<center>
<form>
<input type="text" id="txt">
<input type="button" value="Start stopwatch" onClick="timedCount()">
<p>Click on the Start button above to start the stopwatch.</p>
</form>
<center>
</body>
</html>
////////////////////////////////////
And here is the code for decrementing stopwatch:
////////////////////////////////////
<html>
<head>
<title>stopwatch</title>
</head>
<script type="text/javascript">
var c=60
var t
function stopCount()
{
clearTimeout(t)
}
function timedCount()
{
document.getElementById('txt').value=c
c=c-1
if(c==-1)
{
alert("time over")
stopcount()
}
t=setTimeout("timedCount()",1000)
}
</script>
<body>
<center>
<form>
<input type="text" id="txt">
<input type="button" value="Start stopwatch" onClick="timedCount()">
<p>Click on the Start button above to start the stopwatch.</p>
</form>
<center>
</body>
</html>
please give comments and advices even if you liked it or not.