Jump to navigation

Class: Question

Numbas.Question

new Question(number, examopt, groupopt, gscopeopt, storeopt)

Keeps track of all info to do with an instance of a single question

Parameters:
Name Type Attributes Default Description
number Number

index of this question in the exam (starting at 0)

exam Numbas.Exam <optional>

parent exam

group Numbas.QuestionGroup <optional>

group this question belongs to

gscope Numbas.jme.Scope <optional>
Numbas.jme.builtinScope

global JME scope

store Numbas.storage.BlankStorage <optional>

the storage engine to use

Source:

Members

adviceDisplayed :Boolean

Has the advice been displayed?

Type:
Source:

answered :Boolean

Has this question been answered satisfactorily?

Type:
Source:

callbacks :Object.<Array.<function()>>

Callbacks to run when various events happen

Type:
Properties:
Name Type Description
HTMLAttached Array.<function()>

Run when the question's HTML has been attached to the page.

variablesGenerated Array.<function()>

Run when the question's variables have been generated.

Source:

marks :Number

Maximum marks available for this question

Type:
Source:

name :String

Name - shouldn't be shown to students

Type:
Source:

number :Number

Position of this question in the exam

Type:
Source:

partDictionary :Object.<Numbas.parts.Part>

Dictionary mapping part addresses (of the form qXpY[gZ]) to Numbas.parts.Part objects.

Type:
Source:

parts :Numbas.parts.Part

Parts belonging to this question, in the order they're displayed.

Type:
Source:

revealed :Boolean

Have the correct answers been revealed?

Type:
Source:

scope :Numbas.jme.Scope

The JME scope for this question. Contains variables, functions and rulesets defined in this question

Type:
Source:

score :Number

Student's score on this question

Type:
Source:

signals :Numbas.schedule.SignalBox

Signals produced while loading this question.

Type:
Source:

submitted :Number

Number of times this question has been submitted.

Type:
Source:

visited :Boolean

Has this question been seen by the student? For determining if you can jump back to this question, when Numbas.Question.navigateBrowse is disabled.

Type:
Source:

xml :Element

XML definition of this question

Type:
Source:

Methods

addPart(part, index)

Add a part to the question

Parameters:
Name Type Description
part Numbas.parts.Part
index Number
Source:

calculateScore()

Calculate the student's total score for this questoin - adds up all part scores

Source:

getAdvice(dontStore)

Show the question's advice

Parameters:
Name Type Description
dontStore Boolean

Don't tell the storage that the advice has been shown - use when loading from storage!

Source:

getPart(path) → {Numbas.parts.Part}

Get the part object corresponding to a path

Parameters:
Name Type Description
path Numbas.parts.partpath
Returns:
Type Description
Numbas.parts.Part
Source:

isDirty() → {Boolean}

Has anything been changed since the last submission? If any part has isDirty set to true, return true.

Returns:
Type Description
Boolean
Source:

leave()

Leave this question - called when moving to another question, or showing an info page.

Source:
See:

leavingDirtyQuestion() → {Boolean}

Show a warning and return true if the question is dirty.

Returns:
Type Description
Boolean
Source:
See:

onHTMLAttached(fn)

Add a callback function to run when the question's HTML is attached to the page

Parameters:
Name Type Description
fn function
Listens to Events:
Deprecated:
Source:

onVariablesGenerated(fn)

Add a callback function to run when the question's variables are generated (but before the HTML is attached)

Parameters:
Name Type Description
fn function
Listens to Events:
Deprecated:
Source:

revealAnswer(dontStore)

Reveal the correct answers to the student

Parameters:
Name Type Description
dontStore Boolean

Don't tell the storage that the advice has been shown - use when loading from storage!

Source:

runPreamble()

Execute the question's JavaScript preamble - should happen as soon as the configuration has been loaded from XML, before variables are generated.

Fires:
Source:

submit()

Submit every part in the question

Source:

updateScore()

Recalculate the student's score, update the display, and notify storage.

Source:

validate() → {Boolean}

Validate the student's answers to the question. True if all parts are either answered or have no marks available.

Returns:
Type Description
Boolean
Source:

Events

functionsLoaded

The question's function definitions have been loaded, but the corresponding Numbas.jme.funcObj objects have not been added to the scope yet.

Listeners of This Event:
Source:
See:

functionsMade

The question's functions have been made and added to the question's scope.

Listeners of This Event:
Source:

generateVariables

Trigger this when you're ready to evaluate the question's variables. In an exam context, the Numbas.Exam object triggers this event. If the question has been created standalone, this event must be triggered in order for the question to finish loading.

Listeners of This Event:
Source:

HTMLAttached

The question's HTML has been generated and attached to the page.

Listeners of This Event:
Source:

partsGenerated

The parts of the question have been generated. If resuming an attempt, the parts have not yet been restored to the saved state.

Listeners of This Event:
Source:
See:

partsResumed

Triggered when resuming a saved attempt: the question's parts have been restored to the saved state.

Source:

preambleLoaded

The question preamble has been loaded but not run yet- this happens before any variables, functions, rulesets or parts are generated.

Listeners of This Event:
Source:
See:

preambleRun

The question preamble has been run.

Source:

ready

The question is fully loaded and ready to use.

Listeners of This Event:
Source:

rulesetsLoaded

The question's ruleset definitions have been loaded, but the Numbas.jme.rules.Ruleset objects have not been added to the scope yet.

Listeners of This Event:
Source:
See:

rulesetsMade

The question's rulesets have been made and added to the question's scope.

Listeners of This Event:
Source:

variableDefinitionsLoaded

The variable definitions have been loaded, but their values have not been generated yet.

Listeners of This Event:
Source:
See:

variablesGenerated

The variables have been generated and added to the scope, and are ready to use.

Listeners of This Event:
Source:

variablesSet

The variables have been evaluated, but Numbas.Question.unwrappedVariables has not been set yet.

Listeners of This Event:
Source: