JavaScript is a high-level, dynamic, and interpreted programming language that is commonly used in web development. It allows developers to create interactive elements and dynamic effects on web pages.
Example
/**
* Author: Matej Lednár
*/
const timeInMinutes = 5; // countdown time in minutes
const ms = timeInMinutes * 1000 * 60; // convert countdown time to ms
const now = Date.now();
const finish = now + ms; // when to stop countdown
timer = setInterval(function () {
const counter = finish - Date.now(); // countdown ms
const min = new Date(counter).getMinutes();
const sec = new Date(counter).getSeconds();
let result;
// add zeros before numbers 00:00 - formatter
result = "0" + min + ":" + (sec < 10 ? "0" + sec : sec);
// don't show min and sec, countdown finished
if (counter < 1) {
result = "00:00";
}
console.log(result);
}, 400);
// stop countdown
setTimeout(() => clearInterval(timer), timeInMinutes * 60 * 1000);