You should be able to do it using the “setInterval” function. “setInterval” requires two parameters - the first one is the function you want to continuously call and the second one is the time between each call in milliseconds.
This is how I would implement it
// Variable to set the countdown time
let countDownTime = 10;
// This will store the id of the interval function
let intervalId;
function Countdown()
{
// Increment the time by 1 sec
countDownTime-=1;
// Check if countdown has still not finished. If it has not, display the number otherwise stop the interval function
if(countDownTime > 0)
{
$w("#countdownText").text = countDownTime.toString();
}
else
{
// This is to stop calling the function after the countdown has reached 0
clearInterval(intervalId);
//Do your code here after the countdown is over
}
}
$w.onReady(function () {
$w("#countdownText").text = countDownTime.toString();
// Call the function every second
intervalId = setInterval(()=>{
Countdown()
}, 1000);
}