View Full Version : broken clock script?


stargrl329
06-15-2003, 08:48 PM
I wrote a JavaScript for a custom clock, and it was working fine, until I modified it, because I wanted one that had AM and PM and not 24-hr. time. But now I can't seem to get it to work... every time I try to open the file in Internet Explorer, the script part doesn't load. Here is the script I'm using:

<script type="text/javascript">
<!--
var thedate = new Date( );
var thehours = thedate.getHours( );
var theminutes = thedate.getMinutes( );
if ( thehours >= 12 )
{
document.write( + thehours -= 13 "<font color=red>:<font color=black>" + theminutes + "PM" );
} else {
document.write( + thehours + "<font color=red>:<font color=black>" + theminutes + "AM" );
}
//-->
</script>

Does anyone know what I did wrong? Thanks for your help :)

׺׷lauren·×º×

amicus
06-17-2003, 10:34 PM
i couldn't figure out why your code wasn't working so i just redid it, i hope you don't mind.

var AM = "am";
var PM = "pm";

var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();

if ( hour == 0 ) {
writeTime( hour + 12, minute, AM );
}
else if ( hour < 12 ) {
writeTime( hour, minute, AM );
}
else if ( hour == 12 ) {
writeTime( hour, minute, PM );
}
else if ( hour >= 12 ) {
writeTime( hour - 12, minute, PM );
}

function writeTime( hour, minute, am_pm ) {
var time = hour + "<font color='#FF0000'>:</font>" + minute + " " + am_pm;

document.write( time );
}