TimFA

08-17-2007, 03:57 PM

Ok, I know next to nothing about JavaScript but I was trying to write a simple clock (my first JavaScript attempt). I can't get it right, I know its most likely simple, but I'm not sure how to fix it. Heres what I have.

<script language="Javascript">

if (getHours( ) = setHours(1))

{ document.write('It is 1 OClock A.M.;')

}

if (getHours( ) = setHours(2))

{ document.write('It is 2 OClock A.M.;')

}

if (getHours( ) = setHours(3))

{ document.write('It is 3 OClock A.M.;')

}

if (getHours( ) = setHours(4))

{ document.write('It is 4 OClock A.M.;')

}

if (getHours( ) = setHours(5))

{ document.write('It is 5 OClock A.M.;')

}

if (getHours( ) = setHours(6))

{ document.write('It is 6 OClock A.M.;')

}

if (getHours( ) = setHours(7))

{ document.write('It is 7 OClock A.M.;')

}

if (getHours( ) = setHours(8))

{ document.write('It is 8 OClock A.M.;')

}

if (getHours( ) = setHours(9))

{ document.write('It is 9 OClock A.M.;')

}

if (getHours( ) = setHours(10))

{ document.write('It is 10 OClock A.M.;')

}

if (getHours( ) = setHours(11))

{ document.write('It is 11 OClock A.M.;')

}

if (getHours( ) = setHours(12))

{ document.write('It is 12 OClock P.M.;')

}

if (getHours( ) = setHours(13))

{ document.write('It is 1 OClock P.M.;')

}

if (getHours( ) = setHours(14))

{ document.write('It is 2 OClock P.M.;')

}

if (getHours( ) = setHours(15))

{ document.write('It is 3 OClock P.M.;')

}

if (getHours( ) = setHours(16))

{ document.write('It is 4 OClock P.M.;')

}

if (getHours( ) = setHours(17))

{ document.write('It is 5 OClock P.M.;')

}

if (getHours( ) = setHours(18))

{ document.write('It is 6 OClock P.M.;')

}

if (getHours( ) = setHours(19))

{ document.write('It is 7 OClock P.M.;')

}

if (getHours( ) = setHours(20))

{ document.write('It is 8 OClock P.M.;')

}

if (getHours( ) = setHours(21))

{ document.write('It is 9 OClock P.M.;')

}

if (getHours( ) = setHours(22))

{ document.write('It is 10 OClock P.M.;')

}

if (getHours( ) = setHours(23))

{ document.write('It is 11 OClock P.M.;')

}

if (getHours( ) = setHours(24))

{ document.write('It is 12 OClock A.M.;')

}

</script>

Please tell me how to improve it...well lets start with getting it working first. :D And yes I know it will rewrite the document, I'm just trying to get it to SOMETHING.

<script language="Javascript">

if (getHours( ) = setHours(1))

{ document.write('It is 1 OClock A.M.;')

}

if (getHours( ) = setHours(2))

{ document.write('It is 2 OClock A.M.;')

}

if (getHours( ) = setHours(3))

{ document.write('It is 3 OClock A.M.;')

}

if (getHours( ) = setHours(4))

{ document.write('It is 4 OClock A.M.;')

}

if (getHours( ) = setHours(5))

{ document.write('It is 5 OClock A.M.;')

}

if (getHours( ) = setHours(6))

{ document.write('It is 6 OClock A.M.;')

}

if (getHours( ) = setHours(7))

{ document.write('It is 7 OClock A.M.;')

}

if (getHours( ) = setHours(8))

{ document.write('It is 8 OClock A.M.;')

}

if (getHours( ) = setHours(9))

{ document.write('It is 9 OClock A.M.;')

}

if (getHours( ) = setHours(10))

{ document.write('It is 10 OClock A.M.;')

}

if (getHours( ) = setHours(11))

{ document.write('It is 11 OClock A.M.;')

}

if (getHours( ) = setHours(12))

{ document.write('It is 12 OClock P.M.;')

}

if (getHours( ) = setHours(13))

{ document.write('It is 1 OClock P.M.;')

}

if (getHours( ) = setHours(14))

{ document.write('It is 2 OClock P.M.;')

}

if (getHours( ) = setHours(15))

{ document.write('It is 3 OClock P.M.;')

}

if (getHours( ) = setHours(16))

{ document.write('It is 4 OClock P.M.;')

}

if (getHours( ) = setHours(17))

{ document.write('It is 5 OClock P.M.;')

}

if (getHours( ) = setHours(18))

{ document.write('It is 6 OClock P.M.;')

}

if (getHours( ) = setHours(19))

{ document.write('It is 7 OClock P.M.;')

}

if (getHours( ) = setHours(20))

{ document.write('It is 8 OClock P.M.;')

}

if (getHours( ) = setHours(21))

{ document.write('It is 9 OClock P.M.;')

}

if (getHours( ) = setHours(22))

{ document.write('It is 10 OClock P.M.;')

}

if (getHours( ) = setHours(23))

{ document.write('It is 11 OClock P.M.;')

}

if (getHours( ) = setHours(24))

{ document.write('It is 12 OClock A.M.;')

}

</script>

Please tell me how to improve it...well lets start with getting it working first. :D And yes I know it will rewrite the document, I'm just trying to get it to SOMETHING.