About Matt's HTML Test

Matt's HTML Test is an online multiple-choice test about HTML and its underlying principles. There are ten questions, and each question has four possible answers. These answers are internally treated as numbers, and the numbers of the correct answers follow a pattern which is described by this expression: (i % 4) + 1, where i is the number of the question.

To take the test, the user goes to the URL to which the previous link points. The user enters his or her name and answers the questions on a standard HTML form. The answers are then submitted as numbers, as described above. The form uses radio buttons for the answer choices.

When the user submits the form, the user's name and answers are submitted to a CGI script called "test_submit". This script verifies that the user entered his or her name, compares the user's answers against the correct answers, tells the user the results along with the correct answers for any questions that were answered incorrectly, and records the user's name and score in a file. The questions and the text for the correct answers are hard-coded into the program, but the numeric answers are not.

Two variables are updated during the loop in which test_submit checks the user's answers. One is $correctly_answered, which is the number of questions the user answered correctly. The other is @incorrect_indices, which is an array of indices into the array that holds the correct answer strings. These same indices also point to the right places in the array that holds the questions. An index, which is the question number minus one, is added to this array for each question that the user answered incorrectly.. These indices can then be used to retrieve the questions and correct answers from their corresponding arrays for the questions that the user answered incorrectly.

After checking the user's answers, test_submit calculates the user's grade and adds a record to a file called test_results. The format of each line in this file is "correct_answers:name", where correct_answers is the number of questions the user answered correctly, and name is the user's name. This file is locked while the new record is appended, to avoid race conditions.

There's also a link on the test form which the user can follow to get statistics about the test. These statistics are generated by another CGI program called "test_stats". This program reads the test_results file and displays the testee's name, number of correct answers, and grade for each testee, as well as the average, highest, and lowest grades. The highest and lowest grades are accompanied by the names of their corresponding testees.