Skip to content

Instantly share code, notes, and snippets.

@dominem
Last active October 31, 2019 22:08
Show Gist options
  • Save dominem/bdddf00aa294eb8d6e0055289707f300 to your computer and use it in GitHub Desktop.
Save dominem/bdddf00aa294eb8d6e0055289707f300 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="counter"></div>
<button id="start">Start</button>
<script>
let counter = 60;
let interval = null;
let counterElement = document.getElementById('counter');
let startElement = document.getElementById('start');
init();
function init() {
counterElement.innerText = counter;
startElement.onclick = count;
}
function subtract() {
counter -= 1;
console.log(counter);
counterElement.innerText = counter;
}
function count() {
interval = setInterval(subtract, 1000);
}
</script>
</body>
</html>
@dominem
Copy link
Author

dominem commented Oct 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment