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. |
Members
advice :string
The question's advice text.
Type:
adviceDisplayed :boolean
Has the advice been displayed?
Type:
answered :boolean
Has this question been answered satisfactorily?
Type:
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. |
currentPart :Numbas.parts.Part
In explore mode, the part that the student is currently looking at.
Type:
extraPartOrder :Array.<number>
The indices in the definition of the extra parts that have been added to this question.
Type:
locked :boolean
Has this question been locked?
Type:
marks :number
Maximum marks available for this question.
Type:
maxMarks :number
Maximum available marks in explore mode.
Type:
number :number
Position of this question in the exam.
Type:
objectiveVisibility :string
When should information about objectives be shown to the student? 'always'
or 'when-active'
.
Type:
partDictionary :Object.<Numbas.parts.Part>
Dictionary mapping part addresses (of the form qXpY[gZ]
) to Numbas.parts.Part
objects.
Type:
partsMode :string
How should parts be shown?
all
- All available parts are generated straight away.explore
- Parts are only generated when required.
Type:
penaltyVisibility :string
When should information about penalties be shown to the student? 'always'
or 'when-active'
.
Type:
revealed :boolean
Have the correct answers been revealed?
Type:
scope :Numbas.jme.Scope
The JME scope for this question. Contains variables, functions and rulesets defined in this question.
Type:
score :number
Student's score on this question.
Type:
statement :string
The question's statement text.
Type:
submitted :number
Number of times this question has been submitted.
Type:
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:
xml :Element
XML definition of this question.
Type:
Methods
addExtensionScopes()
Extend this question's scope with scopes from any extensions used.
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). |
Fires:
- Numbas.Question#event:addExtraPart
Returns:
Type | Description |
---|---|
Numbas.parts.Part |
addPart(part, index)
Add a part to the question.
Parameters:
Name | Type | Description |
---|---|---|
part |
Numbas.parts.Part | |
index |
number |
Fires:
- Numbas.Question#event:addPart
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> |
calculateScore()
Calculate the student's total score for this question - adds up all part scores.
Fires:
- Numbas.Question#event:calculateScore
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 |
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 |
error(message, args, originalErroropt)
Throw an error, with the question's identifier prepended to the message.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string | ||
args |
object | Arguments for the error message. |
|
originalError |
Error |
<optional> |
If this is a re-thrown error, the original error object. |
Fires:
- Numbas.Question#event:error
Throws:
finaliseLoad()
Perform any tidying up or processing that needs to happen once the question's definition has been loaded.
Fires:
- Numbas.Question#event:functionsMade
- Numbas.Question#event:constantsMade
- Numbas.Question#event:rulesetsMade
- Numbas.Question#event:variablesSet
- Numbas.Question#event:variablesGenerated
- Numbas.Question#event:ready
- Numbas.Question#event:variablesTodoMade
Listens to Events:
- Numbas.Question#event:preambleLoaded
- Numbas.Question#event:functionsLoaded
- Numbas.Question#event:rulesetsLoaded
- Numbas.Question#event:generateVariables
- Numbas.Question#event:constantsMade
- Numbas.Question#event:functionsMade
- Numbas.Question#event:rulesetsMade
- Numbas.Question#event:variableDefinitionsLoaded
- Numbas.Question#event:variablesSet
- Numbas.Question#event:variablesGenerated
- Numbas.Question#event:variablesTodoMade
- Numbas.Question#event:partsGenerated
- Numbas.Question#event:ready
- Numbas.Question#event:HTMLAttached
generateVariables()
Generate this question's variables.
Fires:
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! |
Fires:
getObjective(name) → {object}
Get the explore mode objective with the given name.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
Returns:
Type | Description |
---|---|
object |
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 |
getPenalty(name) → {object}
Get the explore mode penalty with the given name.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
Returns:
Type | Description |
---|---|
object |
getScope() → {Numbas.jme.Scope}
Get this question's scope object.
Returns:
Type | Description |
---|---|
Numbas.jme.Scope |
isDirty() → {boolean}
Has anything been changed since the last submission? If any part has isDirty
set to true, return true.
Returns:
Type | Description |
---|---|
boolean |
leave()
Leave this question - called when moving to another question, or showing an info page.
Fires:
- Numbas.Question#event:leave
leavingDirtyQuestion() → {boolean}
Show a warning and return true if the question is dirty.
Fires:
- Numbas.Question#event:leavingDirtyQuestion
Returns:
Type | Description |
---|---|
boolean |
loadFromJSON(data)
Load the question's settings from a JSON object.
Parameters:
Name | Type | Description |
---|---|---|
data |
object |
Fires:
- Numbas.Question#event:preambleLoaded
- Numbas.Question#event:functionsLoaded
- Numbas.Question#event:rulesetsLoaded
- Numbas.Question#event:variableDefinitionsLoaded
- Numbas.Question#event:partsGenerated
Listens to Events:
loadFromXML(xml)
Load the question's settings from an XML
Parameters:
Name | Type | Description |
---|---|---|
xml |
Element |
Fires:
- Numbas.Question#event:preambleLoaded
- Numbas.Question#event:constantsLoaded
- Numbas.Question#event:functionsLoaded
- Numbas.Question#event:rulesetsLoaded
- Numbas.Question#event:variableDefinitionsLoaded
- Numbas.Question#event:partsGenerated
Listens to Events:
lock()
Lock this question - the student can no longer change their answers.
Fires:
- Numbas.Question#event:locked
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:
- Use
Numbas.Question#signals
instead.
- Use
- 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:
- Use
Numbas.Question#signals
instead.
- Use
- Source:
removePart(part)
Remove a part from the question.
Parameters:
Name | Type | Description |
---|---|---|
part |
Numbas.parts.Part |
Fires:
- Numbas.Question#event:removePart
resume()
Load saved data about this question from storage.
Fires:
Listens to Events:
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! |
Fires:
- Numbas.Question#event:revealed
runPreamble()
Execute the question's JavaScript preamble - should happen as soon as the configuration has been loaded from XML, before variables are generated.
Fires:
setCurrentPart(part)
Set the currently displayed part.
Parameters:
Name | Type | Description |
---|---|---|
part |
Numbas.parts.Part |
Fires:
- Numbas.Question#event:setCurrentPart
setErrorCarriedForwardBackReferences()
Set back references for adaptive marking: for each part, maintain a list of other parts which use that part in adaptive marking.
submit()
Submit every part in the question.
Fires:
- Numbas.Question#event:pre-submit
- Numbas.Question#event:post-submit
updateScore()
Recalculate the student's score, update the display, and notify storage.
Fires:
- Numbas.Question#event:updateScore
useExtension(extension)
Record that this question uses the given extension.
Parameters:
Name | Type | Description |
---|---|---|
extension |
string |
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 |
Events
HTMLAttached
The entire question, including each part's HTML, has been generated and attached to the page.
Listeners of This Event:
adviceDisplayed
The question advice has been shown to the student.
constantsLoaded
The custom constant definitions have been loaded.
constantsMade
The custom constants have been evaluated and added to the scope
Listeners of This Event:
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:
functionsMade
The question's functions have been made and added to the question's scope.
Listeners of This Event:
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:
mainHTMLAttached
The question's HTML has been generated and attached to the page.
Listeners of This Event:
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:
partsResumed
Triggered when resuming a saved attempt: the question's parts have been restored to the saved state.
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:
preambleRun
The question preamble has been run.
ready
The question is fully loaded and ready to use.
Listeners of This Event:
- Numbas.Exam#makeQuestionList
- Numbas.Exam#regenQuestion
- Numbas.Question#finaliseLoad
- Numbas.Question#resume
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:
rulesetsMade
The question's rulesets have been made and added to the question's scope.
Listeners of This Event:
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:
- Numbas.Question#finaliseLoad
- Numbas.Question#loadFromJSON
- Numbas.Question#loadFromXML
- Numbas.Question#onVariablesGenerated
variablesSet
The variables have been evaluated, but Numbas.Question.unwrappedVariables
has not been set yet.