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 7 of 7
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts

    can some1 help me debug the .tostring code

    can some please help em debug this code. i can seem to get it working. when i run it it says line 8 data is unidentified

    <html>
    <head>
    <title> Displaying Times and Dates</title>
    </head>
    <body>
    <h1> curent date and time </h1>
    <p>
    <script lanuage =" javascript">
    var now= new date();
    var localtime=now.toString();
    var utctime= now.toGMTString();
    document.write("<b> Localtime:</b>"+ localtime+ "<BR>");
    document.write("<b>UTC time: </b> " = UTCtime+ " </p>");

    </script>

    </body>

    </html>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Smile

    I believe you want
    var localtime=now.toDateString();

    instead of:
    var localtime=now.toString();


  • Users who have thanked jmrker for this post:

    haydar (05-07-2009)

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    I believe you want
    var localtime=now.toDateString();

    instead of:
    var localtime=now.toString();

    iv made a copy of date and put it into variable now

    var now= new date();

    so now i want to convert now which is date to string and store it into
    var localtime:

    var localtime=now.toString();

    mmm
    is my code wrong ?

  • #4
    New Coder
    Join Date
    Mar 2009
    Location
    Michigan
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Your code is fine - just remember that everything in Javascript is case-sensitive.

    IE, you have new date(); instead of new Date();, the "UTCtime" variable is used with different case settings. The error you're getting is because of a stray equals sign in your printed string - you probably typoed that for a + sign. I fixed up the problems and it works fine, so you'll just need to clean up the script and make sure all the cases match. Cheers.

    Also note that "language" is not an attribute of <script>, you need to use <script type="text/javascript"> if you want correct formatting.

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Shinykirby View Post
    Your code is fine - just remember that everything in Javascript is case-sensitive.

    IE, you have new date(); instead of new Date();, the "UTCtime" variable is used with different case settings. The error you're getting is because of a stray equals sign in your printed string - you probably typoed that for a + sign. I fixed up the problems and it works fine, so you'll just need to clean up the script and make sure all the cases match. Cheers.

    Also note that "language" is not an attribute of <script>, you need to use <script type="text/javascript"> if you want correct formatting.
    all the cases match now but still same error. it points me to line var localtime = now.toString();
    and says date ' is ' unidentified

    and i cant see anything wrong with the + signs in my output stray. i had miss types a = insted of + and i corrected that to but still error

    the lanuage attruibue is a script attriubute...
    Last edited by haydar; 05-07-2009 at 06:28 PM.

  • #6
    New Coder
    Join Date
    May 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    ohh got it thanks alot i had date(); and it was meant to be Date(); with capital

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    As has been pointed out, Javascript is case sensitive, and date is not the same as Date, and utctime is not the same as UTCtime.

    Code:
    <html>
    <head>
    <title> Displaying Times and Dates</title>
    </head>
    <body>
    <h1> curent date and time </h1>
    <p>
    
    <script type = "text/javascript">
    var now= new Date();  // note Date has a capital D
    var localtime=now.toDateString();
    var UTCtime= now.toGMTString();
    document.write("<b> Localtime:</b>"+ localtime+ "<BR>");
    document.write("<b>UTC time: </b> " + UTCtime+ " </p>");
    </script>
    
    </body>
    </html>

    You seem not to be able to spell langauge but in any case - one more time - <script language = "javascript"> is deprecated and incorrect.

    There is no attribute "language" it has been deprecated for around 10 years.
    The required attribute is "type" and the type="text/javascript"

    Hence...

    <script type="text/javascript"> is now the correct form


  •  

    Posting Permissions

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