Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    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); 
    
    
    };

  • #4
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    Actually you first declared a global variable then you make that same variable as a parameter thats make the variable "null".

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •