Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Countdown</title>
- </head>
- <body>
- <input type="text" id="time" style="border:3px solid blue; text-align:center; font-size:2em;" disabled="true"/>
- <script>
- //setInterval();
- window.onload = function() {
- countdown(600);
- }
- function countdown(startTime){
- let time = startTime;
- let output = document.getElementById("time");
- let timer = setInterval(tick, 1000);
- function tick() {
- time--;
- if (time <= 0) {
- clearInterval(timer);
- }
- output.value = `${Math.floor(time / 60)}:${('0' + time % 60).slice(-2)}`;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment