<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<body>
<input type= "button" id= "Start" value= "Start timing! "/>
<input type= "text" id= "Time" value= ""/>
<input type= "button" id= "clear" value= "clears the timing! "/>
<script type= "Text/javascript" >
var a = 0;
var flag = false;
var B = document.getElementById ("Time");
var C;
document.getElementById ("Start"). onclick = function () {
if (!flag) {
Flag = true;
document.getElementById ("Start"). Value = "Stop timing!" ";
Time ();
} else {
document.getElementById ("Start"). Value = "Start timing!" ";
Timea ();
}
}
function Time () {
B.value = A;
A = a + 1;
c = setTimeout (time, 1000);
}
function Timea () {
Cleartimeout (c);
Flag = false;
}
document.getElementById ("clear"). onclick = function () {
Clear_time ();
}
function Clear_time () {
Cleartimeout (c);
Flag = false;
A = 0;
B.value = A;
}
</script>
</body>
JS Counter code sharing