Hello, I am getting an error message saying clock is undefined, I am not sure why, here is my code:
<script type ="text/javascript">
var theDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var theMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var birthYear = 1960;
var birthDay = 1;
var birthMonth = 1;
var retirementYear;
var retirementAge = 65;
var timerId;
var firstDate = new Date();
var lastDate = new Date();
var minutes = 1000 * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;
function startClock()
{
birthYear = prompt("Type the 4-digit year of your birth.");
birthMonth = prompt("What month? (1-12)");
birthDay = prompt("What day? (1-31)");
retirementAge = prompt("At what age to you plan to retire?");
retirementYear = birthYear + retirementAge;
firstDate = new Date("birthYear", "birthMonth", "birthDay");
lastDate = new Date("retirementYear", "birthMonth", "birthDay");
timerId = setInterval("showTime()", 1);
}
function stopClock()
{
clearInterval(timerId);
}
function showTime()
{
var now = new Date();
var seconds = ((now.getTime() + (retirementAge * 31556926000)) - now.getTime()) / 1000;
var birthDateDisplay = "" + theDays[now.getDay()] + "," + birthDay + " " + theMonths[birthMonth] + ", " + birthYear;
var retirementDisplay = "" + theDays[now.getDay()] + "," + birthDay + " " + theMonths[birthMonth] + ", " + (birthYear + retirementAge);
clock.txtSecondsFace.value = seconds;
clock.txtMinutesFace.value = seconds / 60;
clock.txtHoursFace.value = (seconds / 60) / 60;
clock.txtDaysFace.value = (seconds / 60 / 60) / 24;
clock.txtYearsFace.value = (seconds / 60 / 60 / 24) / 365;
clock.txtWorkDays.value = retirementForm.txtYearsFace.value * .65;
clock.txtFunDays.value = retirementForm.txtYearsFace.value * .35;
clock.txtBirthDate.value = birthDateDisplay;
clock.txtRetirementDate.value = retirementDisplay;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Retirement</title>
</head>
<body>
<h1>Retirement Countdown</h1>
<br />
<form name = "clock" action = "">
<p>
Click the Start Clock button to begin:
<input name = "btnStartClock" value = "Start Clock" type = "button" onclick = "startClock()" />
<input name = "btnStopClock" value = "Stop Clock" type = "button" onclick = "stopClock()" />
</p>
<p>
Birth Date:
<input name = "txtBirthDate" type = "text" />
</p>
<p>
Retirement Date:
<input name = "txtRetirementDate" type = "text" />
</p>
<p>
<h3>Countdown to Retirement</h3>
</p>
<p>
Seconds:
<input name = "txtSecondsFace" type = "text" />
Minutes:
<input name = "txtMinutesFace" type = "text" />
</p>
<p>
Hours:
<input name = "txtHoursFace" type = "text" />
Days:
<input name = "txtDaysFace" type = "text" />
Years:
<input name = "txtYearsFace" type = "text" />
</p>
<p>
<h3>Work Days Versus Fun Days</h3>
</p>
<p>
A typical full time employee works 65 days out of every 100 days.
</p>
<p>
Work days left:
<input name = "txtWorkDays" type = "text" />
Fun days before retirement:
<input name = "txtFunDays" type = "text" />
</p>
</form>
<p>
<h2>Now that is something to think about!</h2>
</p>