-
-
Save MartaJank/d76b21ca1d56097929b65c2117e41a2f to your computer and use it in GitHub Desktop.
JS | Asynchronous JS and callbacks
This file contains 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
const second = 1000; | |
let counter = 0; | |
function concatZero(num) { // when num = 22 | |
return ('0' + num).slice(-2); // "022" --> "22" | |
} | |
function updateClock() { | |
let dateObj = new Date(); | |
const seconds = dateObj.getSeconds(); | |
const minutes = dateObj.getMinutes(); | |
const hours = dateObj.getHours(); | |
// const miliseconds = dateObj.getMilliseconds(); | |
const timeNow = concatZero(hours) + ':' + concatZero(minutes) + ':' + concatZero(seconds); | |
console.log(timeNow); | |
counter++; | |
if ( counter > 10 ) { | |
clearInterval(clockInterval) | |
} | |
} | |
const clockInterval = setInterval(updateClock, second); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment