Last active
November 23, 2015 19:52
-
-
Save redrambles/8587c45d3f0d7557c98a to your computer and use it in GitHub Desktop.
Make a TimerSkillcrush 102 - Make a Timer// source http://jsbin.com/ticipohuxa
This file contains hidden or 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="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> |
This file contains hidden or 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
| /* | |
| * 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