Hey, I think I must be making a realy stupid mistake here, but I can't figure out what I am doing wrong. I'm making a countdown (based on a script I found) which counts down from x seconds to zero. This is going to show (in my game) how long the workers have to work for new resources.
The JavaScript functions:
<script type="text/javascript">
var time = 360;
function reloadPage()
{
window.location.reload();
} // end reloadPage()
function countdown()
{
if(time > 0)
{
var oneMinute = 60; // minute unit in seconds
var oneHour = 60*60; // hour unit in seconds
var hourfield = Math.floor(time/oneHour);
var minutefield = Math.floor((time-hourfield*oneHour)/oneMinute);
var secondfield = Math.floor(time-hourfield*oneHour-minutefield*oneMinute);
var display = hourfield + " h " + minutefield + " min " + secondfield + " sec ";
document.getElementById("countdown").innerHTML = display;
countdownTimer = setTimeout("countdown()",1000);
time = time - 1;
}
else
{
reloadPage();
}
} // end countdown()
</script>
Show the countdown:
<span id="countdown"></span>
<script type="text/javascript">countdown();</script>