showing results for - "how to make a stopwatch using js"
Alessandra
07 Jan 2021
1var x;
2var startstop = 0;
3
4function startStop() { /* Toggle StartStop */
5
6  startstop = startstop + 1;
7
8  if (startstop === 1) {
9    start();
10    document.getElementById("start").innerHTML = "Stop";
11  } else if (startstop === 2) {
12    document.getElementById("start").innerHTML = "Start";
13    startstop = 0;
14    stop();
15  }
16
17}
18
19
20function start() {
21  x = setInterval(timer, 10);
22} /* Start */
23
24function stop() {
25  clearInterval(x);
26} /* Stop */
27
28var milisec = 0;
29var sec = 0; /* holds incrementing value */
30var min = 0;
31var hour = 0;
32
33/* Contains and outputs returned value of  function checkTime */
34
35var miliSecOut = 0;
36var secOut = 0;
37var minOut = 0;
38var hourOut = 0;
39
40/* Output variable End */
41
42
43function timer() {
44  /* Main Timer */
45
46
47  miliSecOut = checkTime(milisec);
48  secOut = checkTime(sec);
49  minOut = checkTime(min);
50  hourOut = checkTime(hour);
51
52  milisec = ++milisec;
53
54  if (milisec === 100) {
55    milisec = 0;
56    sec = ++sec;
57  }
58
59  if (sec == 60) {
60    min = ++min;
61    sec = 0;
62  }
63
64  if (min == 60) {
65    min = 0;
66    hour = ++hour;
67
68  }
69
70
71  document.getElementById("milisec").innerHTML = miliSecOut;
72  document.getElementById("sec").innerHTML = secOut;
73  document.getElementById("min").innerHTML = minOut;
74  document.getElementById("hour").innerHTML = hourOut;
75
76}
77
78
79/* Adds 0 when value is <10 */
80
81
82function checkTime(i) {
83  if (i < 10) {
84    i = "0" + i;
85  }
86  return i;
87}
88
89function reset() {
90
91
92  /*Reset*/
93
94  milisec = 0;
95  sec = 0;
96  min = 0
97  hour = 0;
98
99  document.getElementById("milisec").innerHTML = "00";
100  document.getElementById("sec").innerHTML = "00";
101  document.getElementById("min").innerHTML = "00";
102  document.getElementById("hour").innerHTML = "00";
103
104}
Till
31 Jul 2016
1//create a function to stop the time function stopTime( ) { 
2/* check if seconds, minutes and hours are not equal to 0 */ 
3<!DOCTYPE html> 
4<html lang="en"> 
5<head> 
6<title> JavaScript Stop Watch </title> 
7<style text="text/css"> 
8  #stopWatch { width: 2100px; 
9height: auto; 
10text-align: center; 
11display: block; 
12padding: 5px; 
13margin: 0 auto; } 
14#timer, #fulltime { width: auto; 
15height: auto; 
16padding: 10px;
17font-weight: bold; 
18font-family: tahoma; 
19display: block;
20border: 1px solid #eee; 
21text-align: center; 
22box-shadow: 0 0 5px #ccc; 
23background: #fbfbf0; 
24color: darkblue; 
25border-bottom:4px solid darkgrey; }
26button { cursor: pointer; font-weight: 700; } 
27#fulltime { display:none; font-size:16px; font-weight:bold; } 
28</style> 
29<script type="text/javascript"> 
30</script> 
31</head> 
32<body> 
33<section id="stopWatch"> 
34<p id="timer"> Time : 00:00:00 </p> 
35<button id="start"> Start </button> 
36<button id="stop"> Stop </button> 
37<p id="fulltime"> </p> 
38</section> 
39<script>
40  if ( seconds !== 0 || minutes !== 0 || hours !== 0 ) { 
41  /* display the full time before reseting the stop watch */ 
42  var fulltime = document .getElementById( "fulltime" );
43  //display the full time fulltime.style.display = "block";
44  var time = gethours + mins + secs; 
45  fulltime.innerHTML = 'Fulltime: ' + time; 
46  // reset the stop watch seconds = 0; minutes = 0; hours = 0; secs = '0' + seconds; mins = '0' + minutes + ': '; gethours = '0' + hours + ': '; /* display the stopwatch after it's been stopped */ var x = document.getElementById ("timer"); var stopTime = gethours + mins + secs; x.innerHTML = stopTime; /* display all stop watch control buttons */ var showStart = document.getElementById ('start'); showStart.style.display = "inline-block"; var showStop = document.getElementById ("stop"); showStop.style.display = "inline-block"; /* clear the stop watch using the setTimeout( ) return value 'clearTime' as ID */ clearTimeout( clearTime ); } // if () } // stopTime() /* you need to call the stopTime( ) function to terminate the stop watch */ window.addEventListener( 'load', function ( ) { var stop = document.getElementById ("stop"); stop.addEventListener( 'click', stopTime ); }); // stopwatch.js end 
47</script>    
48</body> 
49</html> 
50
51
52
53
54
55
56
57
Isaac
06 Apr 2016
1<h1>
2  <span id="hour">00</span> :
3  <span id="min">00</span> :
4  <span id="sec">00</span> :
5  <span id="milisec">00</span>
6</h1>
7
8<button onclick="startStop()" id="start">Start</button>
9<button onclick="reset()">Reset</button>
queries leading to this page
stopwatch in js gamejavascript stopwatch functionhow to make a stopwatch in js 3fstop watch in javascriptstopwatch javascriptjavascript making a stopwatchstopwatch code in javascriptdisplay stopwatch in javascriptstart a stopwatch jsstopwatch object in javascriptstopwatch using html css javascriptstopwatch jsstopwatch using jsjs stopwatch functionstart a stopwatch timer javascriptstopwatch in javascriptstopwatch javascript simplecreate a stopwatch in objects in javascriptchronometer methods javascriptmake stopwatch jsstopwatch javascript examplehow to create a stopwatch to time task javascriptjavascript stopwatch w3schoolsjs stopwatch timerjavascript stopwatch in w3schoolhow to make a simple stopwatch in javascriptjava script stopwatchstopwatch javascripthow to make stopwatch using jsjavascript code for stop watchjavascript stopwatchrun stopwatch javascript inbuilt functionjs stop custom timerjavascript stopwatch librarystopwatch wuth javascriptvanilla js stop watchstopwatch with javascriptsimple stopwatch jsadding a stopwatch in jshow to display stopwatch in javascriptstop watch with stop and start button and taken taken in javascript stopwatch function javascriptjavascript cronometerstopwatch javascript w3schoolscreate a stopwatch in javascript step by step processjavascript stopwatshequivalent stopwatch c 23 in javascripteasiest way to create stopwatchset chronometer jshow to make a stopwatch in js with milisecondstopwatch javascript stopwatchhow to set up a stopwatch in javascriptmake a stopwatch in javascripthow to make stopwatch in javascriptbuilding stopwatch using jsstopwatchscript jsjavascript code stopwatchstop watch in jhsstopwatch timer javascriptjavascript stop watchhow to create a stopwatch in jsjavascript timer stopwatch exampleimplement stopwatch in javascriptstopwatch javascirptstopwatch w3schoolsstopwatch with action in javascripthow to do stopwatch in javascriptsinple js stopwatchstopwatch injsstopwatch using html which takes timer from userstopwatch timer in javascriptmake a stopwatch javascriptjavascript stopwatch timerjs stopwatchjavascrip stop watchstoptimer 28 29 javascriptmake javascript stopwatchmake a stopwatch in js 27javascript stop watch samplemake stopwatch in phow to create a stopwatch in javascriptjavascript stopwatch projectprogram to make stopwatch ja javascriptdisplay a stopwatch javascriptstopwatch in p jsstopwatch in javascript exampleeasiest way to create stopwatch in jshow to build a stopwatch in javascriptjs object stopwatchhow to make 3 stopwatch in javascriptstopwatch source code in javascriptuse stopwatch in jshow to make a stopwatch jsstop watch jsjs stopwwatchjavascript stopwatch examplecreate a stopwatch in javascriptstopwatch implementation in html and jsjavascript start stop timer samplesimple stopwatch using jsjavascript stopwatch downloadweschool stopwatch javascriptcreate stopwatch in javascriptbuilding stopwatch javascriptjavascruipt stopwatchhow to set up a stopwatch on javascriptsimple javascript stopwatch funmctions stopwatch timer using javascriptstopwatch script jsstopwatch js w3show the user a stopwatch jshow to make a stopwatch in javascriptstopwatch timer example code javascripthow to make stopwatch in javascript only javascript codehow to create stopwatch in javascriptstopwatch javascript codehow to make a stopwatch with javascriptjs stopwatch simplehow to make a stopwatch using jsstopwatch functions javascripthow to make a stopwatch javascriptstopwatch using javascript source codecronometer in jssimple js stopwatchstopwatch function in javascripthow to set a stopwatchin jsstop watch on javascript how to create a stopwatch javascipthow to set up a stopwatch score in javascriptstart and stop stopwatch javascriptcreat a stop watch javascript javascript stopwatchstopwatch in javascript codethe fastest way to create stopwatch in jsstop a stopwatch javascriptstart a stopwatch in javascriptstopwatch js logicstopwatch js code javascript stopwatch samplejavascript chronometerhow to set a stopwatch jsstopwatch jshow to show stopwatch in javascripthow to create a stopwatch with javascripthow to make a stipwatch in jscreate stopwatch javascriptstopwatch using html css and javascriptjavscript stopwatchhow to build a stop watch in javascripthow to make a js function for stopwatchhow make a stop watch html and jshow to stop a stopwatch using jscreate stopwatch javascriptstopwatch library in javascriptstopwatch codepin using javascriptcreate a simple stopwatch using jssimple javascript stopwatchhow to make a stopwatch in jssimple stopwatch javascripthow to add the stopwatch in html or jsstopwatch html jshow to make stopwatch in jshow to create stopwatch using javascriptstopwatch in dib jshow to write stopwatch time in javascriptjs create stopwatchhow to implement stopwatch in javascriptstopwatch injs 27start the stop watch from specific time of start at jsmake stopwatch in jssimple stopwatch in javascriptjavascript show stopwatchjavascript stopwatch codehow do you make a stopwatch in javascript 3fstopwatch program in javascriptdisplay stopwatch jsmake stopwatch in javascriptstop watch object javascriptstopwatch in jsstopwatch using javascriptjavaascript stopwatchhow to code a stopwatch in javascriptstopwatch with do whilw javascriptstopwatch with jshow to make a stopwatch using js