Created
August 4, 2016 09:37
-
-
Save baltazarparra/002683a5f341b22043f822f2c904a835 to your computer and use it in GitHub Desktop.
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
(function(window, document){ | |
'use strict'; | |
var $input = document.querySelector('[data-js="input"]'); | |
var $start = document.querySelector('[data-js="start"]'); | |
var $stop = document.querySelector('[data-js="stop"]'); | |
var $reset = document.querySelector('[data-js="reset"]'); | |
var counter = 0; | |
var crono; | |
$start.addEventListener('click', function(event) { | |
event.preventDefault(); | |
function timer() { | |
$input.value = counter++; | |
} | |
crono = setInterval(timer, 100); | |
}, false); | |
$stop.addEventListener('click', function(event) { | |
event.preventDefault(); | |
clearInterval(crono); | |
}, false); | |
$reset.addEventListener('click', function(event) { | |
event.preventDefault(); | |
$input.value = 0; | |
clearInterval(crono); | |
}, false); | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment