Languages
[Edit]
EN

TypeScript - 1 minute countdown timer

0 points
Created by:
Mahir-Bright
1281

In this article, we would like to show you how to create a one-minute countdown timer in TypeScript.

Practical example

In the example below, we use setTimeout() method to execute a function once the timer expires.

As setTimeout() arguments we pass:

  1. makeIteration() function that prints seconds and clears the console from the previous iteration,
  2. 1000 milliseconds to make setTimeout() count every second. 
let seconds: number = 60;

const makeIteration = (): void => {
    console.clear();
    if (seconds > 0) {
        console.log(seconds);
        setTimeout(makeIteration, 1000); // 1 second waiting
    }
    seconds -= 1;
};

setTimeout(makeIteration, 1000); // 1 second waiting

See also

  1. JavaScript - 1 minute countdown timer

  2. Dirask Snippets - js for loop with settimeout() example

References

  1. setTimeout() - Web APIs | MDN

Alternative titles

  1. TypeScript - one minute countdown timer
  2. TypeScript - 60 seconds countdown timer
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join