-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #389 from srinjoy-26/st
Vanilla stopwatch
- Loading branch information
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
# vanilla stopwatch using javascript | ||
## tech stack | ||
- HTML | ||
- CSS | ||
- JS | ||
## look | ||
![Screenshot 2022-05-30 192855](https://user-images.githubusercontent.com/91176055/171007729-a6910b61-42d6-48de-9ab3-7de9ae0b9cca.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>stopwatch</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="stop"> | ||
<span id="Hour">00</span>: | ||
<span id="Min">00</span>: | ||
<span id="Sec">00</span>. | ||
<span id="Ms">00</span> | ||
</div> | ||
<div class="button"> | ||
<button id="start">start</button> | ||
<button id="stop">stop</button> | ||
<button id="Reset">Reset</button> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
let Ms = 0; | ||
let Min = 0; | ||
let Hour = 0; | ||
let Sec = 0; | ||
|
||
let MsString = document.getElementById('Ms'); | ||
let SecString = document.getElementById('Sec'); | ||
let HourString = document.getElementById('Hour'); | ||
let MinString = document.getElementById('Min'); | ||
|
||
let startBtn = document.getElementById('start'); | ||
let stopBtn = document.getElementById('stop'); | ||
let ResetBtn = document.getElementById('Reset'); | ||
|
||
let interval; | ||
|
||
function stopw(){ | ||
Ms++; | ||
if(Ms == 100){ | ||
Ms = 0; | ||
Sec++; | ||
MsString.innerHTML = Ms; | ||
} | ||
if(Sec == 60){ | ||
Sec = 0; | ||
Min++; | ||
SecString.innerHTML = Sec; | ||
} | ||
if(Min == 60){ | ||
Min = 0; | ||
Hour++; | ||
MinString.innerHTML = Min; | ||
} | ||
if(Ms < 10){ | ||
MsString.innerHTML = '0' + Ms; | ||
} | ||
else{ | ||
MsString.innerHTML = Ms; | ||
} | ||
if(Sec < 10){ | ||
SecString.innerHTML = '0' + Sec; | ||
} | ||
else{ | ||
SecString.innerHTML = Sec; | ||
} | ||
if(Min < 10){ | ||
MinString.innerHTML = '0' + Min; | ||
} | ||
else{ | ||
MinString.innerHTML = Min; | ||
} | ||
if(Hour < 10){ | ||
HourString.innerHTML = '0' + Hour; | ||
} | ||
else{ | ||
HourString.innerHTML = Hour; | ||
} | ||
} | ||
function startTimer(){ | ||
clearInterval(interval); | ||
interval = setInterval(stopw, 10); | ||
} | ||
function stopTimer(){ | ||
clearInterval(interval); | ||
|
||
} | ||
|
||
function resetTimer(){ | ||
clearInterval(interval); | ||
Ms = 0; | ||
Sec = 0; | ||
Min = 0; | ||
Hour = 0; | ||
|
||
MsString.innerHTML = '00'; | ||
SecString.innerHTML = '00'; | ||
MinString.innerHTML = '00'; | ||
HourString.innerHTML = '00'; | ||
} | ||
|
||
startBtn.addEventListener('click', startTimer); | ||
stopBtn.addEventListener('click', stopTimer); | ||
ResetBtn.addEventListener('click', resetTimer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
body{ | ||
height: 100vh; | ||
background-color: #0a1e29; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-direction: column; | ||
font-family: sans-serif; | ||
} | ||
.stop{ | ||
color: #fff; | ||
font-size: 5em; | ||
} | ||
.button button{ | ||
background-color: #fff; | ||
border: none; | ||
border-radius: 10px; | ||
padding: 10px; | ||
font-size: 1.25em; | ||
font-weight: 600 ; | ||
margin: 0 10px; | ||
cursor: pointer; | ||
} | ||
#start{ | ||
background-color: aquamarine; | ||
} | ||
#stop{ | ||
background-color: yellow; | ||
} | ||
#Reset{ | ||
background-color: red; | ||
} |