Skip to content

Instantly share code, notes, and snippets.

@redrambles
Last active November 23, 2015 19:52
Show Gist options
  • Select an option

  • Save redrambles/8587c45d3f0d7557c98a to your computer and use it in GitHub Desktop.

Select an option

Save redrambles/8587c45d3f0d7557c98a to your computer and use it in GitHub Desktop.
Make a TimerSkillcrush 102 - Make a Timer// source http://jsbin.com/ticipohuxa
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Skillcrush 102 - Make a Timer" />
<title>Make a Timer</title>
</head>
<body>
<h1>Make a Timer</h1>
<div id="timer"></div>
<script id="jsbin-javascript">
/*
* Set the time in seconds.
*/
var time = 3;
/*
* Select the timer element to keep track of progress.
*/
var timer = document.getElementById("timer");
/*
* Count down from the time specified, updating the DOM every second.
*
* THIS IS WHERE YOU WRITE YOUR CODE!
*
* If you need to change the text of the timer, you can do so like this:
* timer.innerText = yourVariableName;
*/
setInterval ( function() {
if (time < 0){
return;
}
timer.innerText = time;
time -= 1;
}, 1000);
</script>
</body>
</html>
/*
* Set the time in seconds.
*/
var time = 3;
/*
* Select the timer element to keep track of progress.
*/
var timer = document.getElementById("timer");
/*
* Count down from the time specified, updating the DOM every second.
*
* THIS IS WHERE YOU WRITE YOUR CODE!
*
* If you need to change the text of the timer, you can do so like this:
* timer.innerText = yourVariableName;
*/
setInterval ( function() {
if (time < 0){
return;
}
timer.innerText = time;
time -= 1;
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment