Homework

 

 

 <HTML><HEAD>
<TITLE>JavaScript Timer</TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript --------

var timerID = null
var startDate
var startSecs

function startclock()
{
startDate = new Date()
startSecs = (startDate.getHours()*60*60) + 
(startDate.getMinutes()*60) +
startDate.getSeconds()
showtime()
}
/* -------------------------------------------------
showtime()
Puts the amount of time that has passed since 
loading the page into the field named timerField in 
the form named timeForm 
------------------------------------------------ */
function showtime()
{
// this doesn't work correctly at midnight...

var now = new Date()
var nowSecs = (now.getHours()*60*60) + 
(now.getMinutes()*60) + 
now.getSeconds()
var elapsedSecs = nowSecs - startSecs;

var hours = Math.floor( elapsedSecs / 3600 )
elapsedSecs = elapsedSecs - (hours*3600)

var minutes = Math.floor( elapsedSecs / 60 )
elapsedSecs = elapsedSecs - (minutes*60)

var seconds = elapsedSecs

var timeValue = "" + hours
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds

// Update display
document.timerForm.timerField.value = timeValue 
timerID = setTimeout("showtime()",1000)
}
// -- End of JavaScript code -------------- -->
</SCRIPT>
<META HTTP-EQUIV="Refresh" CONTENT="3600; URL=AA.html">
</HEAD>
<BODY onLoad="startclock()" BGCOLOR="#cccccc" TEXT="#000000" 
LINK="#336699" VLINK="#666666" ALINK="#FF9933">

<FORM NAME="timerForm"> 
<FONT FACE="Arial,Helvetica" SIZE="-1"><B>You have a total of 60 
minutes to complete this test. &#160;Time spent so far: </FONT>
<INPUT TYPE="text" NAME="timerField" SIZE=10 VALUE ="">
</FORM>

</HTML>