Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let opoznienie=setInterval(funkcja,10);
- let ms=0, h=0, m=0, s=0;
- let uchwyt=""
- document.addEventListener("DOMContentLoaded" , przyciski , false)
- function przyciski()
- {
- a=document.getElementById("start");
- b=document.getElementById("stop");
- c=document.getElementById("reset");
- c.addEventListener("click",function(){reset()},false)
- b.addEventListener("click",function(){stop()},false)
- a.addEventListener("click",function(){start()},false)
- }
- function stop()
- {
- clearInterval(opoznienie);
- }
- function start()
- {
- opoznienie=setInterval(funkcja,10);
- }
- function reset()
- {
- ms=0;h=0;m=0;s=0;
- document.getElementById("stoper").innerHTML="00:00:00:00";
- }
- function funkcja()
- {
- uchwyt=""
- ms++
- if(ms>=100)
- {
- s++;
- ms=0;
- if(s>=60)
- {
- m++;
- s=0;
- if(m>=60)
- {
- h++;
- }
- }
- }
- if(h<10)
- {
- uchwyt+="0";
- }
- uchwyt+=h+":";
- if(m<10)
- {
- uchwyt+="0";
- }
- uchwyt+=m+":";
- if(s<10)
- {
- uchwyt+="0";
- }
- uchwyt+=s+":";
- if(ms<10)
- {
- uchwyt+="0";
- }
- uchwyt+=ms;
- document.getElementById("stoper").innerHTML=uchwyt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement