The Irish History Quiz is an XHTML document containing both standard XHTML coding and JavaScript for interactivity. The quiz presents a set of ten questions related to Irish history, each with three possible answers, and the option for the user's answers to be scored, with a percentage correct and all incorrect answers noted. The user can opt to retake the quiz if he or she has chosen wrong answers for any of the questions.
The JavaScript contained in the document makes use of the following:
quiz()alert()[one for each "if" statement]reload() [i.e. document.reload()]onClickiresult1result2result3result4result5result6result7result8result9result10perIn the XHTML document, the <head> area contains meta elements providing author, contributor, title, keyword, abstract and a JavaScript (see below). The <body> contains eleven form elements, "form1"-"form10" and "total." Each of the "form1"-"form10" consists of a checkbox (for error reporting), a text question, and a "select" list of three options, with values 1-3 (the default "Choose an answer" has a value of 0 - see below). The user chooses one of the three possible answers. The last form, "total," contains two buttons with JavaScript event handlers (onClick), "Submit" and "Retake Quiz," which respectively initiate the JavaScript program in the document head or reload (reset) the page. Finally, a set of three text boxes are filled in by the script upon the user clicking the "Submit" button, providing the number of correct answers, the total number possible, and a percentage correct. If the user has missed filling on or more of the forms, alert boxes will pop up to warn the user that "Question n was not answered;" no score will be provided until the user has selected answers for all questions.
The JavaScript is triggered by the buttons contained within the "total" form near the end of the document.
result1-result10 (initially set to zero by:var resultN=document.formN.answerN.selectedIndexif (result N==0)", which invoke the:alert ("Question n was not answered")<input type="text" name="score" value="" size="5" /> out of <input type="text" name="outof" value="10" size="5" /> correct.document.total.percent.value. This value is output to the user in the next statement:<input type="text" name="percent" value="" size="9" /> %checked='yes'" if the resultN does not exactly match the value given for each statement.location.reload() with the event handler "onClick." This function reloads the document and resets all variables to their initial state.