Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions Simple Stopwatch/Stopwatch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stopwatch</title>
<style>
body {
background: black;
height: 100%;
}
.container {
width: 800px;
margin: 150px auto;
color: #fff;
text-align: center;
}
h2 {
font-family: "Roboto", sans-serif;
font-weight: 100;
font-size: 2.6em;
text-transform: uppercase;
}
#seconds,
#tens,
.dots {
font-size: 2em;
font-weight: bold;
}
button {
border-radius: 5px;
background: white;
color: black;
border: 1px solid #fff;
text-decoration: none;
cursor: pointer;
font-size: 1.2em;
padding: 18px 10px;
width: 150px;
margin: 10px;
outline: none;
margin-top: 20px;
}
button:hover {
transition: all 0.5s ease-in-out;
background: black;
color: white;
border: 1px solid #fff;
}
</style>
</head>
<body>
<div class="container">
<h2>JavaScript Stopwatch Project</h2>
<p>
<span id="seconds">00</span><span class="dots">:</span
><span id="tens">00</span>
</p>
<button id="button-start">Start</button>
<button id="button-stop">Stop</button>
<button id="button-reset">Reset</button>
</div>

<script>
var seconds = 0;
var tens = 0;

var appendTens = document.getElementById("tens");
var appendSeconds = document.getElementById("seconds");
var buttonStart = document.getElementById("button-start");
var buttonStop = document.getElementById("button-stop");
var buttonReset = document.getElementById("button-reset");

var Interval;

function startTimer() {
tens++;
if (tens < 9) {
appendTens.innerHTML = "0" + tens;
}
if (tens > 9) {
appendTens.innerHTML = tens;
}
if (tens > 99) {
seconds++;
appendSeconds.innerHTML = "0" + seconds;
tens = 0;
appendTens.innerHTML = "0" + tens;
}
if (seconds > 9) {
appendSeconds.innerHTML = seconds;
}
}

buttonStart.onclick = function () {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
};

buttonStop.onclick = function () {
clearInterval(Interval);
};

buttonReset.onclick = function () {
clearInterval(Interval);
tens = "00";
seconds = "00";
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
};
</script>
</body>
</html>