...

View Full Version : can some1 help me debug the .tostring code



haydar
05-07-2009, 05:58 PM
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>

jmrker
05-07-2009, 06:03 PM
I believe you want
var localtime=now.toDateString();

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

:thumbsup:

haydar
05-07-2009, 06:07 PM
I believe you want
var localtime=now.toDateString();

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

:thumbsup:

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 ?

Shinykirby
05-07-2009, 06:15 PM
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.

haydar
05-07-2009, 06:25 PM
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...

haydar
05-07-2009, 06:36 PM
ohh got it thanks alot i had date(); and it was meant to be Date(); with capital

Philip M
05-07-2009, 06:48 PM
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.


<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum