Advertisement
angryatti

TimerMethod-PreAlpha

Jul 14th, 2024 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="hu">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Timer</title>
  8.  
  9. </head>
  10.  
  11. <body>
  12.  
  13.     <div id="timer">00 : 00 : 00,0</div>
  14.  
  15.     <button type="button" onclick="change() == 'Start' ? clearInterval(myTimer) : myTimer = setInterval(timer,100);"
  16.         name="timerid" id="timerid">Start</button>
  17.  
  18.     <script type="text/javascript">
  19.  
  20.  
  21.         var myTimer = 0;
  22.  
  23.         num = 0;
  24.  
  25.         function timer() {
  26.  
  27.             num++;
  28.             b = Math.floor(num / 60 / 60 / 10);
  29.             num0 = num - b * 60 * 60 * 10
  30.  
  31.             c = Math.floor(num0 / 60 / 10);
  32.             num0 = num0 - c * 60 * 10
  33.  
  34.             d = Math.floor(num0 / 10);
  35.             e = num0 - d * 10
  36.  
  37.             if (b < 10) {
  38.                 b = "0" + b;
  39.             }
  40.  
  41.             if (c < 10) {
  42.                 c = "0" + c;
  43.             }
  44.  
  45.             if (d < 10) {
  46.                 d = "0" + d;
  47.             }
  48.  
  49.             document.getElementById("timer").innerHTML = b + " : " + c + " : " + d + "," + e;
  50.         }
  51.         function change() {
  52.             let item = document.getElementById("timerid");
  53.  
  54.             if (item.innerHTML == "Start") {
  55.  
  56.                 item.innerHTML = "Stop";
  57.  
  58.             }
  59.             else {
  60.                 item.innerHTML = "Start";
  61.             }
  62.  
  63.             return item.innerHTML;
  64.         }
  65.     </script>
  66.  
  67. </body>
  68.  
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement