Author Topic: find the js mistake  (Read 421 times)

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
find the js mistake
« on: January 18, 2009, 05:21:11 AM »
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:
Code: [Select]
<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:
Code: [Select]
<span id="countdown"></span>
<script type="text/javascript">countdown();</script>


Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: find the js mistake
« Reply #1 on: January 18, 2009, 08:17:38 AM »
It's fixed. Like I thought it was a VERY stupid mistake :D. Well, I'm glad it was, so it's also easy fixed ^^.

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: find the js mistake
« Reply #2 on: January 19, 2009, 07:06:39 AM »
lol gotta hate when that happens :p
Idiocy - Never underestimate the power of stupid people in large groups.


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal