Created
March 25, 2018 19:37
-
-
Save eli-oat/e6959b202840373d9611b026bfee5621 to your computer and use it in GitHub Desktop.
Stopwatch [A wicked simple stopwatch] // source https://jsbin.com/yubaki
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[A wicked simple stopwatch]"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Stopwatch</title> | |
</head> | |
<body> | |
<h1>Stopwatch</h1> | |
<p> | |
<span id="minutes">00</span>: | |
<span id="seconds">00</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> | |
<script id="jsbin-javascript"> | |
window.onload = function() { | |
var minutes = 00; | |
var seconds = 00; | |
var tens = 00; | |
var appendMinutes = document.getElementById("minutes"); | |
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; | |
buttonStart.onclick = function() { | |
clearInterval(Interval); | |
Interval = setInterval(startTimer, 10); | |
} | |
buttonStop.onclick = function() { | |
clearInterval(Interval); | |
} | |
buttonReset.onclick = function() { | |
clearInterval(Interval); | |
tens = "00"; | |
seconds = "00"; | |
minutes = "00"; | |
appendTens.innerHTML = tens; | |
appendSeconds.innerHTML = seconds; | |
appendMinutes.innerHTML = minutes; | |
} | |
function startTimer() { | |
tens++; | |
if (tens < 9) { | |
appendTens.innerHTML = "0" + tens; | |
} | |
if (tens > 9) { | |
appendTens.innerHTML = tens; | |
} | |
if (tens > 99) { | |
console.log("seconds"); | |
seconds++; | |
appendSeconds.innerHTML = "0" + seconds; | |
tens = 0; | |
appendTens.innerHTML = "0" + 0; | |
} | |
if (seconds > 9) { | |
appendSeconds.innerHTML = seconds; | |
} | |
if (seconds > 60) { | |
console.log("minutes"); | |
minutes++; | |
appendMinutes.innerHTML = '0' + minutes; | |
seconds = 0; | |
appendSeconds.innerHTML = '0' + 0; | |
} | |
if (minutes > 9) { | |
appendMinutes.innerHTML = minutes; | |
} | |
} | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">window.onload = function() { | |
var minutes = 00; | |
var seconds = 00; | |
var tens = 00; | |
var appendMinutes = document.getElementById("minutes"); | |
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; | |
buttonStart.onclick = function() { | |
clearInterval(Interval); | |
Interval = setInterval(startTimer, 10); | |
} | |
buttonStop.onclick = function() { | |
clearInterval(Interval); | |
} | |
buttonReset.onclick = function() { | |
clearInterval(Interval); | |
tens = "00"; | |
seconds = "00"; | |
minutes = "00"; | |
appendTens.innerHTML = tens; | |
appendSeconds.innerHTML = seconds; | |
appendMinutes.innerHTML = minutes; | |
} | |
function startTimer() { | |
tens++; | |
if (tens < 9) { | |
appendTens.innerHTML = "0" + tens; | |
} | |
if (tens > 9) { | |
appendTens.innerHTML = tens; | |
} | |
if (tens > 99) { | |
console.log("seconds"); | |
seconds++; | |
appendSeconds.innerHTML = "0" + seconds; | |
tens = 0; | |
appendTens.innerHTML = "0" + 0; | |
} | |
if (seconds > 9) { | |
appendSeconds.innerHTML = seconds; | |
} | |
if (seconds > 60) { | |
console.log("minutes"); | |
minutes++; | |
appendMinutes.innerHTML = '0' + minutes; | |
seconds = 0; | |
appendSeconds.innerHTML = '0' + 0; | |
} | |
if (minutes > 9) { | |
appendMinutes.innerHTML = minutes; | |
} | |
} | |
}</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
window.onload = function() { | |
var minutes = 00; | |
var seconds = 00; | |
var tens = 00; | |
var appendMinutes = document.getElementById("minutes"); | |
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; | |
buttonStart.onclick = function() { | |
clearInterval(Interval); | |
Interval = setInterval(startTimer, 10); | |
} | |
buttonStop.onclick = function() { | |
clearInterval(Interval); | |
} | |
buttonReset.onclick = function() { | |
clearInterval(Interval); | |
tens = "00"; | |
seconds = "00"; | |
minutes = "00"; | |
appendTens.innerHTML = tens; | |
appendSeconds.innerHTML = seconds; | |
appendMinutes.innerHTML = minutes; | |
} | |
function startTimer() { | |
tens++; | |
if (tens < 9) { | |
appendTens.innerHTML = "0" + tens; | |
} | |
if (tens > 9) { | |
appendTens.innerHTML = tens; | |
} | |
if (tens > 99) { | |
console.log("seconds"); | |
seconds++; | |
appendSeconds.innerHTML = "0" + seconds; | |
tens = 0; | |
appendTens.innerHTML = "0" + 0; | |
} | |
if (seconds > 9) { | |
appendSeconds.innerHTML = seconds; | |
} | |
if (seconds > 60) { | |
console.log("minutes"); | |
minutes++; | |
appendMinutes.innerHTML = '0' + minutes; | |
seconds = 0; | |
appendSeconds.innerHTML = '0' + 0; | |
} | |
if (minutes > 9) { | |
appendMinutes.innerHTML = minutes; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment