JavaScript setTimeout Example
HTML
<div id="output"></div>
CSS
<style>
#output{
width: 200px;
word-wrap: break-word;
}
</style>
JavaScript
<script>
document.addEventListener('DOMContentLoaded',(e)=>{
let output=document.querySelector("#output");
(function timer() {
setTimeout(function(){
let min=1;
let max=10;
let rand=Math.floor(Math.random() * (max - min) ) + min;
output.innerHTML+=rand;
timer();
}, 100);
})();
});
</script>
<div id="timer"></div>
<script>
document.addEventListener('DOMContentLoaded',(e)=>{
(function timer() {
setTimeout(function(){
let min=1;
let max=10;
let time=document.querySelector("#timer");
let d=new Date();
time.innerHTML=`${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}`;
timer();
},1000);
})();
});
</script>
Comments 0