O'Reilly logo

JavaScript Application Cookbook by Jerry Bradenbaugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required