setTimeOut - it call to function and execute our codes after a few menutes.
Additionally setTimeOut accepts these values
How it works ?
setTimeOut(()=>{console.log("Hello khusi")}, 8000);
and result showed after 8 secound.
.
We can type the third value as so.
setTimeout((text)=>{console.log("Hello khusi"+ text)}, 8000, "program");
and it demonstrate
setInterval - it works during the time that we add.
Secondly, setInterval take this kind of properties.
How does it work ?
"use-strict";
let btn=document.getElementById('start');
let timeText=document.getElementById('time');
let stopbtn=document.getElementById('stop')
let timer=0;
let timeCount=setInterval(()=>{
timeText.innerHTML=`${timer}`;
timer++;
}, 1000);
btn.addEventListener('click',()=>{
setInterval(()=>{
timeText.innerHTML=`${timer}`;
timer++;
}, 1000);
});
stopbtn.addEventListener('click', ()=>{
clearInterval(timeCount)
})
Firstly it started to count automatically
then we stop it with stop button by clicking
after that we again start to continue by clicking start button
Top comments (0)