Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84ff009

Browse files
stopwatch
1 parent 9524d09 commit 84ff009

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

‎StopWatchProject/app.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
let min_html = document.getElementById('min');
2+
let sec_html = document.getElementById('seconds');
3+
let milli_html = document.getElementById('milliseconds');
4+
5+
let watchInterval ;
6+
7+
let minutes = 0;
8+
let seconds = 0;
9+
let milliseconds = 0;
10+
function start(){
11+
watchInterval = setInterval(function(){
12+
milliseconds++
13+
if(milliseconds >= 99){
14+
seconds++
15+
milliseconds = 0
16+
}
17+
if(seconds >= 59){
18+
minutes++
19+
seconds = 0
20+
}
21+
milli_html.innerText = milliseconds
22+
sec_html.innerText = seconds < 10 ? '0' + seconds : seconds
23+
min_html.innerText = minutes < 10 ? '0' + minutes : minutes
24+
}, 10);
25+
}
26+
function stop(){
27+
clearInterval(watchInterval)
28+
}
29+
function reset(){
30+
clearInterval(watchInterval)
31+
minutes = 0 ;
32+
seconds = 0 ;
33+
milliseconds = 0 ;
34+
35+
milli_html.innerText = milliseconds
36+
sec_html.innerText = seconds
37+
min_html.innerText = minutes
38+
}

‎StopWatchProject/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>STOP WATCH</title>
7+
</head>
8+
<body>
9+
<h1 style="text-align: center;">STOP WATCH</h1>
10+
<div style="display: flex;justify-content: center;">
11+
<h3 id="min">00</h3>
12+
<h3>:</h3>
13+
<h3 id="seconds">00</h3>
14+
<h3>:</h3>
15+
<h3 id="milliseconds">00</h3>
16+
</div>
17+
<div style="display: flex;justify-content: center;">
18+
<button onclick="start()">Start</button>
19+
<button onclick="stop()">Stop</button>
20+
<button onclick="reset()">Reset</button>
21+
</div>
22+
<script src="app.js"></script>
23+
</body>
24+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /