Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="utf-8">
- <title>rafal</title>
- </head>
- <body>
- <form name="form_main">
- <div>
- <span id="hour">00</span>:<span id="minute">00</span>:<span id="second">00</span>:<span id="millisecond">000</span> <br>
- </div>
- <button type="button" id="start" name="start">kilk1</button>
- </form>
- <script>
- let hour = 0;
- let minute = 0;
- let second = 0;
- let millisecond = 0;
- let cron;
- document.form_main.start.onclick = () => start();
- document.getElementById("start").ondblclick = function() { pause() };
- function start() {
- pause();
- cron = setInterval(() => { timer(); }, 10);
- }
- function pause() {
- clearInterval(cron);
- }
- function reset() {
- hour = 0;
- minute = 0;
- second = 0;
- millisecond = 0;
- document.getElementById('hour').innerText = '00';
- document.getElementById('minute').innerText = '00';
- document.getElementById('second').innerText = '00';
- document.getElementById('millisecond').innerText = '000';
- }
- function timer() {
- if ((millisecond += 10) == 1000) {
- millisecond = 0;
- second++;
- }
- if (second == 60) {
- second = 0;
- minute++;
- }
- if (minute == 60) {
- minute = 0;
- hour++;
- }
- document.getElementById('hour').innerText = returnData(hour);
- document.getElementById('minute').innerText = returnData(minute);
- document.getElementById('second').innerText = returnData(second);
- document.getElementById('millisecond').innerText = returnData(millisecond);
- }
- function returnData(input) {
- return input >= 10 ? input : `0${input}`
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement