Advertisement
pvpunikalnypvp

Untitled

Dec 13th, 2022
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>rafal</title>
  6. </head>
  7. <body>
  8. <form name="form_main">
  9. <div>
  10. <span id="hour">00</span>:<span id="minute">00</span>:<span id="second">00</span>:<span id="millisecond">000</span> <br>
  11. </div>
  12.  
  13. <button type="button" id="start" name="start">kilk1</button>
  14.  
  15. </form>
  16. <script>
  17. let hour = 0;
  18. let minute = 0;
  19. let second = 0;
  20. let millisecond = 0;
  21.  
  22. let cron;
  23.  
  24. document.form_main.start.onclick = () => start();
  25. document.getElementById("start").ondblclick = function() { pause() };
  26.  
  27.  
  28. function start() {
  29. pause();
  30. cron = setInterval(() => { timer(); }, 10);
  31. }
  32.  
  33. function pause() {
  34. clearInterval(cron);
  35. }
  36.  
  37. function reset() {
  38. hour = 0;
  39. minute = 0;
  40. second = 0;
  41. millisecond = 0;
  42. document.getElementById('hour').innerText = '00';
  43. document.getElementById('minute').innerText = '00';
  44. document.getElementById('second').innerText = '00';
  45. document.getElementById('millisecond').innerText = '000';
  46. }
  47.  
  48. function timer() {
  49. if ((millisecond += 10) == 1000) {
  50. millisecond = 0;
  51. second++;
  52. }
  53. if (second == 60) {
  54. second = 0;
  55. minute++;
  56. }
  57. if (minute == 60) {
  58. minute = 0;
  59. hour++;
  60. }
  61. document.getElementById('hour').innerText = returnData(hour);
  62. document.getElementById('minute').innerText = returnData(minute);
  63. document.getElementById('second').innerText = returnData(second);
  64. document.getElementById('millisecond').innerText = returnData(millisecond);
  65. }
  66.  
  67. function returnData(input) {
  68. return input >= 10 ? input : `0${input}`
  69. }
  70.  
  71. </script>
  72.  
  73.  
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement