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

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

exam Numbas.Exam <optional>

The parent exam.

group Numbas.QuestionGroup <optional>

The group this question belongs to.

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

The global JME scope.

store Numbas.storage.BlankStorage <optional>

The storage engine to use.

Source:

Members

advice :string

The question's advice text.

Type:
Source:

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:

currentPart :Numbas.parts.Part

In explore mode, the part that the student is currently looking at.

Type:
Source:

extraPartOrder :Array.<number>

The indices in the definition of the extra parts that have been added to this question.

Type:
Source:

locked :boolean

Has this question been locked?

Type:
Source:

marks :number

Maximum marks available for this question.

Type:
Source:

maxMarks :number

Maximum available marks in explore mode.

Type:
Source:

name :string

The question's name.

Type:
Source:

number :number

Position of this question in the exam.

Type:
Source:

objectiveVisibility :string

When should information about objectives be shown to the student? 'always' or 'when-active'.

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:

partsMode :string

How should parts be shown?

  • all - All available parts are generated straight away.
  • explore - Parts are only generated when required.
Type:
Source:

penaltyVisibility :string

When should information about penalties be shown to the student? 'always' or 'when-active'.

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:

statement :string

The question's statement text.

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

addExtraPart(def_index, scope, variables, previousPartopt, indexopt) → {Numbas.parts.Part}

Create a part whose definition is at the given index in the question's definition, using the given scope, and add it to this question. The question's variables are remade using the given dictionary of changed variables.

Parameters:
Name Type Attributes Description
def_index number

The index of the part's definition in the question's list of part definitions.

scope Numbas.jme.Scope
variables object.<Numbas.jme.token>
previousPart Numbas.parts.Part <optional>

The part that this part follows on from.

index number <optional>

The position of the part in the parts list (added to the end if not given).

Returns:
Type Description
Numbas.parts.Part
Source:

addPart(part, index)

Add a part to the question.

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

allParts() → {Array.<Numbas.parts.Part>}

A list of all parts in the question which can be answered by the student: top-level parts, gaps and steps. Doesn't include alternative versions of parts.

Returns:
Type Description
Array.<Numbas.parts.Part>
Source:

calculateScore()

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

Source:

createExtraPartFromJSON(json_index, scope, variables, previousPartopt, indexopt) → {Numbas.parts.Part}

Create a part with the given JSON definition, using the given scope, and add it to this question. The question's variables are remade using the given dictionary of changed variables.

Parameters:
Name Type Attributes Description
json_index number

The index of the part's definition in the JSON.

scope Numbas.jme.Scope
variables object.<Numbas.jme.token>
previousPart Numbas.parts.Part <optional>

The part that this part follows on from.

index number <optional>

The position of the part in the parts list (added to the end if not given).

Returns:
Type Description
Numbas.parts.Part
Source:

createExtraPartFromXML(xml_index, scope) → {Numbas.parts.Part}

Create an extra part with the given XML definition, using the given scope.

Parameters:
Name Type Description
xml_index number

The index of the part's definition in the XML.

scope Numbas.jme.Scope
Returns:
Type Description
Numbas.parts.Part
Source:

generateVariables()

Generate this question's variables.

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:

getObjective(name) → {object}

Get the explore mode objective with the given name.

Parameters:
Name Type Description
name string
Returns:
Type Description
object
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:

getPenalty(name) → {object}

Get the explore mode penalty with the given name.

Parameters:
Name Type Description
name string
Returns:
Type Description
object
Source:

getScope() → {Numbas.jme.Scope}

Get this question's scope object.

Returns:
Type Description
Numbas.jme.Scope
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:

lock()

Lock this question - the student can no longer change their answers.

Source:

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:

removePart(part)

Remove a part from the question.

Parameters:
Name Type Description
part Numbas.parts.Part
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:

setCurrentPart(part)

Set the currently displayed part.

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

setErrorCarriedForwardBackReferences()

Set back references for adaptive marking: for each part, maintain a list of other parts which use that part in adaptive marking.

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

adviceDisplayed

The question advice has been shown to the student.

Source:

constantsLoaded

The custom constant definitions have been loaded.

Source:

constantsMade

The custom constants have been evaluated and added to the scope

Listeners of This Event:
Source:

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 entire question, including each part's HTML, has been generated and attached to the page.

Listeners of This Event:
Source:

mainHTMLAttached

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: