Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2012, 09:18 PM   PM User | #1
kiwis
New Coder

 
Join Date: Mar 2007
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
kiwis is an unknown quantity at this point
what's wrong with this, it doesn't do anything

Code:
<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>
kiwis is offline   Reply With Quote
Old 11-04-2012, 09:30 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
You never call the function in the first place.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-05-2012, 03:29 PM   PM User | #3
yaseenyahya
New to the CF scene

 
Join Date: Oct 2012
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
yaseenyahya is an unknown quantity at this point
Code:
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 is offline   Reply With Quote
Old 11-05-2012, 04:08 PM   PM User | #4
yaseenyahya
New to the CF scene

 
Join Date: Oct 2012
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
yaseenyahya is an unknown quantity at this point
Actually you first declared a global variable then you make that same variable as a parameter thats make the variable "null".
yaseenyahya is offline   Reply With Quote
Old 11-05-2012, 06:41 PM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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:

Code:
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();
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:08 AM.


Advertisement
Log in to turn off these ads.