Introduction to Computer Programming

Homework 6

The goal of this exercise is to learn how computer programs can make decisions and perform different operations depending on the results of those decisions. You will demonstrate this by improving the clock you constructed in the previous exercise to add a functioning AM/PM indicator, and you will make the colon between the minutes and seconds display blink on and off once each second.


In the previous exercise you created a working digital clock which should look something like this:

To this clock you should now add the following features:

  1. The hours display should be a number from zero to twelve, inclusive, and numbers less than ten should have a leading zero.
  2. Similarly, the day of the month and the minutes display should also have leading zeros for values less than ten.
  3. There should be an AM/PM indicator between the year and hour, similar to what is shown in the example above, with a bright green dot which correctly indicates whether the current time is AM or PM.
  4. The AM/PM indicator labels should use a white sans-serif font on a dark red background to match the labels above each display element.
  5. There should be a colon (or two dots) between the hours and minutes displays which should blink on and then off again once per second.
  6. To make sure the display is accurate, the clock refresh rate should be at least every tenth of a second, if not more frequent.


Your code will have to make several decisions, such as "is the current time before or after noon?" or "is this number less than ten?". You can learn more about hot to do this by reading in your textbook about the "if" statement in JavaScript.


The name of the file for this web page should be your first name, followed by the initial letter of your last name, followed by the two digits "06". The file extension should be ".html". So, for example, a student by the name of Hedy Lamar would create a file called "HedyL06.html".

To submit your assignment you should print a copy of the source code file, and print a copy of the resulting "output" (what it looks like in a browser). Staple the two together, with the ouput page on top, and put your name on the top of the first page.

You should also upload a copy of your file to