administer.html

The objects are now in place. Let’s put them to work for us. This is another application where the JavaScript brains reside in the upper frame, and the lower frame is used for interaction. You can break down the application into a series of processes. Table 2.1 lists and describes these processes and includes the JavaScript variables and functions associated with each.

Table 2-1. Test Processes and Associated JavaScript Functions

Process

Description

Associated JavaScript

Setting the environment

Declare and initialize global variables, shuffle the question-answer sets.

variables qIdx, correct, howMany, stopOK, nextQ, results, aFrame, qFrame

arrays keeper, rank, questions, answers

functions itemReset(), shuffle()

Administering the test

Write each question-answer set to the window, record each user choice.

functions buildQuestion(), makeButton(), possibly chickenOut()

Grading the test

Compare student answers with correct answers.

function gradeTest()

Printing out results

Print out all answers, right and wrong, to the window along with a ranking.

function printResults()

Displaying explanations

Printing and clearing explanations to parent.frame[1].

functions explain() and show().

Resetting the environment

Set all necessary variables to their original values.

variables qIdx, correct, stopOK

array keeper

functions cleanSlate(), shuffle()

We’ll look at each of these in a moment. For now, check out the code for administer.html in Example ...

Get JavaScript Application Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.