File tree Expand file tree Collapse file tree 3 files changed +140
-0
lines changed
Fronted Projects/stopwatch Expand file tree Collapse file tree 3 files changed +140
-0
lines changed Original file line number Diff line number Diff line change 1+ * {
2+ margin : 0 ;
3+ padding : 0 ;
4+ box-sizing : border-box;
5+ }
6+
7+ body {
8+ background-color : rgb (240 , 133 , 34 );
9+ color : white;
10+ text-align : center;
11+ }
12+ .container {
13+ width : 100% ;
14+ height : 100vh ;
15+ display : flex;
16+ justify-content : center;
17+ align-items : center;
18+ }
19+ # main p {
20+ padding-bottom : 20px ;
21+ font-size : 25px ;
22+ }
23+ # main b {
24+ font-family : sans-serif;
25+ font-size : 80px ;
26+ text-size-adjust : 30px ;
27+ padding-bottom : 10px ;
28+ }
29+ # main span {
30+ display : flex;
31+ flex-direction : row;
32+ justify-content : space-between;
33+ height : 50px ;
34+ }
35+ # main span div button {
36+ height : 100% ;
37+ width : 120px ;
38+ font-size : 20px ;
39+ color : white;
40+ background-color : transparent;
41+ border : 2px solid white;
42+ border-radius : 50px ;
43+ }
44+ # main span div button : focus {
45+ animation-delay : 2s ;
46+ background-color : white;
47+ color : rgb (240 , 133 , 34 ) ;
48+ outline : none;
49+ }
Original file line number Diff line number Diff line change 1+ <!Doctype html>
2+ < html >
3+ < head >
4+ < title > js-stopwatch</ title >
5+ < link rel ="stylesheet " type ="text/css " href ="stopwatch.css ">
6+ </ head >
7+ < body >
8+ < section class ="container ">
9+ < div id ="main ">
10+ < b > STOPWATCH</ b >
11+ < p id ="display "> 00:00:00</ p >
12+ < span >
13+ < div >
14+ < button id ="jstart " onclick ="clockstart() "> START</ button >
15+ </ div >
16+ < div >
17+ < button id ="jstop " onclick ="clockstop() "> STOP</ button >
18+ </ div >
19+ < div >
20+ < button id ="jreset " onclick ="clockreset() "> RESET</ button >
21+ </ div >
22+ </ span >
23+ </ div >
24+ </ section >
25+ < script src ="stopwatch.js "> </ script >
26+ </ body >
27+ </ html >
Original file line number Diff line number Diff line change 1+ //define var to hold values
2+ let sec = 00 ;
3+ let min = 00 ;
4+ let hr = 00 ;
5+
6+ let displaysec = 0 ;
7+ let displaymin = 0 ;
8+ let displayhr = 0 ;
9+
10+ var interval = null ;
11+ var status = "stopped" ;
12+
13+
14+ function stopwatch ( ) {
15+ sec ++ ;
16+ if ( sec / 60 === 1 ) {
17+ min ++ ;
18+ sec = 0 ;
19+
20+ if ( min / 60 === 1 ) {
21+ hr ++ ;
22+ min = 0 ;
23+
24+
25+ }
26+ }
27+
28+ if ( sec < 10 ) {
29+ displaysec = "0" + sec . toString ( ) ;
30+ } else {
31+ displaysec = sec ;
32+ }
33+ if ( min < 10 ) {
34+ displaymin = "0" + min . toString ( ) ;
35+ } else {
36+ displaymin = min ;
37+ }
38+ if ( hr < 10 ) {
39+ displayhr = "0" + hr . toString ( ) ;
40+ } else {
41+ displayhr = hr ;
42+ }
43+
44+ //display time values
45+ document . getElementById ( "display" ) . innerHTML = displayhr + ":" + displaymin + ":" + displaysec ;
46+
47+ }
48+
49+ function clockstart ( ) {
50+ if ( status == "stopped" ) {
51+ interval = window . setInterval ( stopwatch , 1000 ) ;
52+ status = "started" ;
53+ }
54+ }
55+ function clockstop ( ) {
56+ status = "stopped" ;
57+ window . clearInterval ( interval ) ;
58+ }
59+ function clockreset ( ) {
60+ status = "stopped" ;
61+ window . clearInterval ( interval ) ;
62+ document . getElementById ( "display" ) . innerHTML = "00:00:00" ;
63+ sec = 0 ; min = 0 ; hr = 0 ;
64+ }
You can’t perform that action at this time.
0 commit comments