...

View Full Version : what's wrong with this, it doesn't do anything



kiwis
11-04-2012, 10:18 PM
<script type="text/javascript">

var GameDate = new Date("January 01, 1970 00:00:00");

function GameTimer(GameDate){

GameDate.setMonth(GameDate.getMonth()+1);
document.getElementById('demo').innerHTML = GameDate;

var GameDateTimer = setTimeout('GameTimer(GameDate)', 1000);

}
</script>

felgall
11-04-2012, 10:30 PM
You never call the function in the first place.

yaseenyahya
11-05-2012, 04:29 PM
var GameDate = new Date("January 01, 1970 00:00:00");
function GameTimer(){

GameDate.setMonth(GameDate.getMonth()+1);

document.getElementById('demo').innerHTML = GameDate;

var GameDateTimer = setTimeout('GameTimer()', 1000);


};

yaseenyahya
11-05-2012, 05:08 PM
Actually you first declared a global variable then you make that same variable as a parameter thats make the variable "null".

felgall
11-05-2012, 07:41 PM
Since GameTimer() never gets called only the first statement actually gets run (as I said before - simply repeating the same post where it doesn't get called doesn't change anything).

The only actual call to GameTimer() is inside an implied evil eval inside of the GameTimer() function itself so as it never gets called in the first place that never gets run either.

To get it to run (and to get rid of the unnecessary implied eval) you need it coded like this:


var GameDate = new Date("January 01, 1970 00:00:00");
function GameTimer(){

GameDate.setMonth(GameDate.getMonth()+1);

document.getElementById('demo').innerHTML = GameDate;

var GameDateTimer = setTimeout(GameTimer, 1000);


};

GameTimer();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum