Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Last active March 12, 2021 06:38
Show Gist options
  • Select an option

  • Save bogoreh/9c1f40230752f06cdce1a2d5f764235e to your computer and use it in GitHub Desktop.

Select an option

Save bogoreh/9c1f40230752f06cdce1a2d5f764235e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Spin-off of "Challenge: Stopwatch"</title>
</head>
<body>
<button id="stop-button" type="button">Stop</button>
<p>
<span id="seconds">0</span> seconds have gone by!
</p>
<script>
// Make it count up on a timer, calling this function
var seconds = document.getElementById("seconds");
var countUp = function() { // ?
seconds.textContent = parseFloat (seconds.textContent) + 1;
};
var timer = window.setInterval(countUp, 1000);
// How can you make it stop counting?
var stopCountUp = function() {
window.clearInterval(timer);
};
var stopButton = document.getElementById("stop-button");
stopButton.addEventListener("click", stopCountUp);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment