---
title: "How do you create a timer using JavaScript?"  
description: "How do you create a timer using JavaScript?"  
author: "ICSM Computer"  
published: 2024-10-17  
updated: 2024-11-20  
canonical: https://www.mindstick.com/forum/161009/how-do-you-create-a-timer-using-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# How do you create a timer using JavaScript?

How do you create a [timer](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript), Just like a [calendar](https://www.mindstick.com/articles/13088/how-to-choose-the-best-calendar-for-you-dynamics-crm-system) flips on every [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society)?

## Just like,

![How do you create a timer using JavaScript?](https://www.mindstick.com/mindstickforums/1a3959b7-78f6-4130-aa1b-696bfa0cd8a5/images/5ab6f30a-9edb-4dba-8164-db331fa480c8.png)

## Replies

### Reply by Anubhav Sharma

Creating a timer in JavaScript is quite straightforward. Here’s a simple example of how you can create a countdown timer:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Countdown Timer</title>
</head>
<body>
    <div id="timer">10:00</div>
    <script>
        // Set the countdown time in seconds
        let time = 600; // 10 minutes

        // Function to update the timer
        function updateTimer() {
            let minutes = Math.floor(time / 60);
            let seconds = time % 60;

            // Add leading zeros if needed
            minutes = minutes < 10 ? '0' + minutes : minutes;
            seconds = seconds < 10 ? '0' + seconds : seconds;

            // Display the timer
            document.getElementById('timer').textContent = minutes + ':' + seconds;

            // Decrease the time by one second
            time--;

            // Stop the timer when it reaches zero
            if (time < 0) {
                clearInterval(timerInterval);
                document.getElementById('timer').textContent = "Time's up!";
            }
        }

        // Update the timer every second
        let timerInterval = setInterval(updateTimer, 1000);
    </script>
</body>
</html>
```

This code sets up a simple countdown timer that starts from 10 minutes and updates every second. When the timer reaches zero, it stops and displays “Time’s up!”.

Feel free to ask if you need any more details or have other questions!


---

Original Source: https://www.mindstick.com/forum/161009/how-do-you-create-a-timer-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
