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 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Why won't this work

    <script language="Javascript">
    function test()
    {var today = new Date();
    mo = today.getMonth();
    yr = today.getFullYear();
    if (yr = 2006)
    document.write(mo);
    if (yr = 2005)
    document.write(yr)};
    </script>

  • #2
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Checkout code below....
    Code:
    var today = new Date();
    var mo = today.getMonth();
    var yr = today.getYear();
    
    if (yr == "2006")
    document.write(mo);
    if (yr == "2005") 
    document.write(yr);
    By the way the answer will always be 2005 becuase present year is 2005.

    Have a nice day

    Afru.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Nope, getFullYear() is a valid method. The errors lays only in the bitwise comparation

    if (yr == 2006){
    document.write(mo);}
    if (yr == 2005){
    document.write(yr);}

    getYear() might return '05' in Moz or similar;
    Last edited by Kor; 03-15-2005 at 05:42 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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