Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
JavaScript Doesn't Work?
So, My code is the top one and the tutorial code is at the bottom.
Is there any reason my code (the top code) not work? I'm sure this is an obvious mistake.
Thank you.
A few Notes:
I used the Tryit Editor v1.4
I found the tutorial here:
http://www.pageresource.com/jscript/jclock.htm
<HTML>
<HEAD>
<script language="text/javascript">
function startclock()
{
var date = new Date ();
var hour = date.getHours ();
var min = date.getMinutes ();
var sec = date.getSeconds ();
var AMorPM = " ";
if (hour>12)
AMorPM = "P.M.";
else
AMorPM = "A.M.";
if (hour>13)
hour-=12;
if (hour==0)
hour = 12;
if (min<10)
min="0"+min;
if (sec<10)
sec="0"+sec;
document.clockform.clockhere.value=hour+":"+min+":"+sec+" "+AMorPM;
setTimeout('startclock()',1000);
}
</script>
</HEAD>
<BODY onLoad="startclock();">
<FORM Name="clockform">
Current Time in Chicago: <input type="text" name="clockhere" size="15">
<HEAD>
<SCRIPT language="JavaScript">
<!--
function startclock()
{
var thetime=new Date();
var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var AorP=" ";
if (nhours>=12)
AorP="P.M.";
else
AorP="A.M.";
if (nhours>=13)
nhours-=12;
if (nhours==0)
nhours=12;
if (nsecn<10)
nsecn="0"+nsecn;
if (nmins<10)
nmins="0"+nmins;
document.clockform.clockspot.value=nhours+":"+nmins+":"+nsecn+" "+AorP;
setTimeout('startclock()',1000);
}
//-->
</SCRIPT>
</HEAD>
<BODY onLoad="startclock()">
<FORM name="clockform">
Current Time: <INPUT TYPE="text" name="clockspot" size="15">
</FORM>
</BODY>
</html>
2 Answers
- Anonymous1 decade agoFavorite Answer
Your code is truncated. Therefore it is difficult to answer this question. The proper use of white space would have prevented this problem.
That said, you have a number of minor syntax errors, such as not properly writing your method and object calls, bad control structures, etc.
<script type="text/javascript">
function startclock() {
var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var part;
if (hour > 12) {
part = "P.M.";
}
else {
part = "A.M.";
}
if (hour > 13) { hour -= 12; }
if (hour == 0) { hour = 12; }
if (min < 10) { min = "0" + min; }
if (sec < 10) { sec = "0" + sec; }
document.clockform.clockhere.value = hour + ":" + min + ":" + sec + " " + part;
setTimeout('startclock()', 1000);
}