Help with Javascript countdown timer

Hi all,

This is my first post on a forum regarding help so I’m sorry in advance.

I currently have a text based MMORPG.

I am trying to create a countdown timer for my functions(Crime, Car Steal and so on)


  window.setTimeout("Tick()", 1000);

    function Tick() {
        window.setTimeout("Tick()", 1000);
    }
	var Timer;
var TotalSeconds;


function CreateTimer(TimerID, Time) {
    Timer = document.getElementById(TimerID);
    TotalSeconds = Time;
    
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function Tick() {
    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    Timer.innerHTML = TotalSeconds;
}

function Tick() {
    if (TotalSeconds <= 0) {
        alert("Available")
        return;
    }

    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    var Seconds = TotalSeconds;
    
	var Days = Math.floor(Seconds / 86400);
    Seconds -= Days * 86400;
	
    var Hours = Math.floor(Seconds / 3600);
    Seconds -= Hours * (3600);

    var Minutes = Math.floor(Seconds / 60);
    Seconds -= Minutes * (60);


    var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds)


    Timer.innerHTML = TimeStr + "Organised Robbery!";
}


function LeadingZero(Time) {

    return (Time < 10) ? "0" + Time : + Time;

}

Any help would be greatly appreciated.

So do you want a timer that after a certain time, it performs a function?

Does the timer need a countdown?

Sponsor our Newsletter | Privacy Policy | Terms of Service