Jump to navigation

Class: MultipleResponsePart

Numbas.parts.MultipleResponsePart

new MultipleResponsePart(pathopt, question, parentPart, storeopt)

Multiple choice part - either pick one from a list, pick several from a list, or match choices with answers (2d grid, either pick one from each row or tick several from each row)

Types:

  • 1_n_2: pick one from a list. Represented as N answers, 1 choice
  • m_n_2: pick several from a list. Represented as N answers, 1 choice
  • m_n_x: match choices (rows) with answers (columns). Represented as N answers, X choices.
Parameters:
Name Type Attributes Default Description
path Numbas.parts.partpath <optional>
'p0'
question Numbas.Question
parentPart Numbas.parts.Part
store Numbas.storage.BlankStorage <optional>
Source:

Members

(static) layoutTypes :Object.<function()>

Layouts for multiple response types

Type:
Source:

answered :Boolean

Has this part been answered?

Type:
Inherited From:
Source:

creditFraction :Numbas.math.Fraction

Credit as a fraction. Used to avoid simple floating point errors.

Type:
Inherited From:
Source:

customName :String

Custom name for this part, or null if none. Variables will be substituted into this string from the part's scope.

Type:
Inherited From:
Source:

display :Numbas.display.PartDisplay

Associated display object. It is not safe to assume this is always present - in the editor, parts have no display.

Type:
Inherited From:
Source:

doesMarking :Boolean

Does this mark do any marking? False for information only parts

Type:
Inherited From:
Source:

finalised_result :Numbas.marking.finalised_state

The result of the last marking run

Type:
Inherited From:
Source:

flipped :Boolean

Have choice and answers been swapped (because of the weird settings for 1_n_2 and m_n_2 parts)

Type:
Source:

gaps :Array.<Numbas.parts.Part>

Child gapfill parts

Type:
Inherited From:
Source:

isDirty :Boolean

Has the student changed their answer since last submitting?

Type:
Inherited From:
Source:

markingFeedback :Array.<Numbas.parts.feedbackmessage>

Messages explaining how marks were awarded

Type:
Inherited From:
Source:

markingScript :Numbas.marking.MarkingScript

The script to mark this part - assign credit, and give messages and feedback.

Type:
Inherited From:
Source:

marks :Number

Maximum marks available for this part

Type:
Inherited From:
Source:

name :String

A readable name for this part, to show to the student. Change it with Numbas.parts.Part#setName

Type:
Inherited From:
Source:

numAnswers :Number

Number of answers

Type:
Source:

numChoices :Number

Number of choices - used by m_n_x parts

Type:
Source:

parentPart :Numbas.parts.Part

Reference to parent of this part, if this is a gap or a step

Type:
Inherited From:
Source:

path :Numbas.parts.partpath

A question-wide unique 'address' for this part.

Type:
Inherited From:
Source:

question :Numbas.Question

The question this part belongs to

Type:
Inherited From:
Source:

score :Number

Student's score on this part

Type:
Inherited From:
Source:

settings

Properties set when the part is generated Extends Numbas.parts.Part#settings

Properties:
Name Type Description
maxMarksEnabled Boolean

is there a maximum number of marks the student can get?

minAnswersString String

minimum number of responses the student must select, without variables substituted in.

maxAnswersString String

maximum number of responses the student must select, without variables substituted in.

minAnswers Number

minimum number of responses the student must select. Generated from minAnswersString.

maxAnswers Number

maximum number of responses the student must select. Generated from maxAnswersString.

shuffleChoices String

should the order of choices be randomised?

shuffleAnswers String

should the order of answers be randomised?

matrix Array.<Array.<Number>>

marks for each answer/choice pair. Arranged as matrix[answer][choice]

displayType String

how to display the response selectors. Can be radiogroup, checkbox or dropdownlist.

displayColumns Number

how many columns to use to display the choices

warningType String

what to do if the student picks the wrong number of responses? Either none (do nothing), prevent (don't let the student submit), or warn (show a warning but let them submit)

layoutType String

The kind of layout to use. See Numbas.parts.MultipleResponsePart.layoutTypes

layoutExpression JME

Expression giving a 2d array or matrix describing the layout when layoutType is 'expression'.

Overrides:
Source:

shouldResubmit :Boolean

True if this part should be resubmitted because another part it depended on has changed

Type:
Inherited From:
Source:

stagedAnswer :Array.<String>

Student's answers as visible on the screen (not necessarily yet submitted)

Type:
Inherited From:
Source:

steps :Array.<Numbas.parts.Part>

Child step parts

Type:
Inherited From:
Source:

stepsMarks :Number

Marks available for the steps, if any

Type:
Inherited From:
Source:

stepsOpen :Boolean

Is the steps display open? (Students can toggle it, but that doesn't affect whether they get the penalty)

Type:
Inherited From:
Source:

stepsShown :Boolean

Have the steps been show for this part?

Type:
Inherited From:
Source:

ticks :Array.<Array.<Boolean>>

Student's last submitted answer/choice selections

Type:
Source:

type :String

This part's type, e.g. "jme", "numberentry", ...

Type:
Inherited From:
Source:

useCustomName :Boolean

Should a custom name be used?

Type:
Inherited From:
Source:

warnings :Array.<String>

Warnings shown next to the student's answer

Type:
Inherited From:
Source:

xml :Element

XML defining this part

Type:
Inherited From:
Source:

Methods

addCredit(credit, message)

Add an absolute value to credit

Parameters:
Name Type Description
credit Number

amount to add

message String

message to show in feedback to explain this action

Inherited From:
Source:

addStep(step, index)

Add a step to this part

Parameters:
Name Type Description
step Numbas.parts.Part
index Number

position of the step

Inherited From:
Source:

addVariableReplacement(variable, part, must_go_first)

Add a variable replacement for this part's adaptive marking

Parameters:
Name Type Description
variable String

the name of the variable to replace

part String

the path of the part to use

must_go_first Boolean

Must the referred part be answered before this part can be marked?

Inherited From:
Source:

apply_feedback(feedback)

Apply a finalised list of feedback states to this part.

Parameters:
Name Type Description
feedback Array.<Numbas.marking.feedback_item>
Inherited From:
Source:
See:

applyScoreLimits()

Make sure the awarded score is between the minimum and maximum available.

Inherited From:
Source:

assignName(index, siblings) → {Boolean}

Assign a name to this part

Parameters:
Name Type Description
index Number

the number of parts before this one that have names.

siblings Number

the number of siblings this part has

Returns:
Type Description
Boolean

true if this part has a name that should increment the label counter

Inherited From:
Source:

baseMarkingScript() → {Numbas.marking.MarkingScript}

The script to mark this part - assign credit, and give messages and feedback.

Returns:
Type Description
Numbas.marking.MarkingScript
Overrides:
Source:

calculateScore()

Calculate the student's score based on their submitted answers

Calls the parent part's calculateScore method at the end.

Inherited From:
Source:

error(message, args, originalErroropt)

Throw an error, with the part'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

Throws:
Inherited From:
Source:

errorCarriedForwardScope() → {Numbas.jme.Scope}

Replace variables with student's answers to previous parts

Returns:
Type Description
Numbas.jme.Scope
Inherited From:
Source:

finaliseLoad()

Perform any tidying up or processing that needs to happen once the part's definition has been loaded

Overrides:
Source:

getCorrectAnswer(scope) → {matrix}

Compute the correct answer, based on the given scope - a matrix filled with 1 for choices that should be selected, and 0 otherwise.

Parameters:
Name Type Description
scope Numbas.jme.Scope
Returns:
Type Description
matrix
Overrides:
Source:

getScope() → {Numbas.jme.Scope}

Get a JME scope for this part. If this.question is set, use the question's scope. Otherwise, use Numbas.jme.builtinScope.

Returns:
Type Description
Numbas.jme.Scope
Inherited From:
Source:

giveWarning(warning)

Give the student a warning about this part.

Parameters:
Name Type Description
warning String
Inherited From:
Source:
See:

hasStagedAnswer() → {Boolean}

Has the student entered an answer to this part?

Returns:
Type Description
Boolean
Inherited From:
Source:
See:

hideSteps()

Close the steps box. This doesn't affect the steps penalty.

Inherited From:
Source:

input_options() → {Object}

Options for this part's input widget

Returns:
Type Description
Object
Overrides:
Source:

input_widget() → {String}

The name of the input widget this part uses, if any.

Returns:
Type Description
String
Overrides:
Source:

loadFromJSON(data)

Load the part's settings from a JSON object

Parameters:
Name Type Description
data Object
Overrides:
Source:

loadFromXML(xml)

Load the part's settings from an XML node

Parameters:
Name Type Description
xml Element
Overrides:
Source:

mark(scope) → {Numbas.marking.finalised_state}

Function which marks the student's answer: run this.settings.markingScript, which sets the credit for the student's answer to a number between 0 and 1 and produces a list of feedback messages and warnings. If the question has been answered in a way that can be marked, this.answered should be set to true.

Parameters:
Name Type Description
scope Numbas.jme.Scope
Returns:
Type Description
Numbas.marking.finalised_state
Inherited From:
Source:
See:

mark_answer(studentAnswer, scope) → {Numbas.marking.marking_script_result}

Run the marking script against the given answer. This does NOT apply the feedback and credit to the part object, it just returns it.

Parameters:
Name Type Description
studentAnswer Numbas.jme.token
scope Numbas.jme.Scope
Returns:
Type Description
Numbas.marking.marking_script_result
Inherited From:
Source:
See:

markAgainstScope(scope, feedback) → {Numbas.parts.marking_results}

Calculate the correct answer in the given scope, and mark the student's answer

Parameters:
Name Type Description
scope Numbas.jme.Scope

scope in which to calculate the correct answer

feedback Object.<Array.<String>>

dictionary of existing warnings and markingFeedback lists, to add to - copies of these are returned with any additional feedback appended

Returns:
Type Description
Numbas.parts.marking_results
Inherited From:
Source:

markingComment(message)

Add a comment to the marking feedback

Parameters:
Name Type Description
message String
Inherited From:
Source:

multCredit(factor, message)

Multiply credit by the given amount - use to apply penalties

Parameters:
Name Type Description
factor Number
message String

message to show in feedback to explain this action

Inherited From:
Source:

openSteps()

Open the steps, either because the student asked or the answers to the question are being revealed. This doesn't affect the steps penalty.

Inherited From:
Source:

pleaseResubmit()

Called by another part when its marking means that the marking for this part might change (i.e., when this part replaces a variable with the answer from the other part) Sets this part as dirty, and gives a warning explaining why the student must resubmit.

Inherited From:
Source:

(abstract) rawStudentAnswerAsJME() → {Numbas.jme.token}

Get the student's answer as it was entered as a JME data type, to be used in the custom marking algorithm

Returns:
Type Description
Numbas.jme.token
Overrides:
Source:

removeWarnings()

Remove all warnings

Inherited From:
Source:
See:

resume()

Load saved data about this part from storage The part is not resubmitted - you must do this afterwards, once any steps or gaps have been resumed.

Overrides:
Source:

revealAnswer()

Reveal the correct answers, and any distractor messages for the student's choices Extends Numbas.parts.Part.revealAnswer

Overrides:
Source:

setCredit(credit, message, reason)

Set the credit to an absolute value

Parameters:
Name Type Description
credit Number
message String

message to show in feedback to explain this action

reason String

why was the credit set to this value? If given, either 'correct' or 'incorrect'.

Inherited From:
Source:

setDirty(dirty)

Call when the student changes their answer, or submits - update Numbas.parts.Part.isDirty

Parameters:
Name Type Description
dirty Boolean
Inherited From:
Source:

setMarkingScript(markingScriptString, extend_base)

Set this part's JME marking script

Parameters:
Name Type Description
markingScriptString String
extend_base Boolean

Does this script extend the built-in script?

Inherited From:
Source:

setScript(name, order, script)

Set a custom JavaScript script

Parameters:
Name Type Description
name String

the name of the method to override

order String

When should the script run? 'instead', 'before' or 'after'

script String

the source code of the script

Inherited From:
Source:
See:

setStudentAnswer()

Save a copy of the student's answer as entered on the page, for use in marking.

Overrides:
Source:

setWarnings(warnings)

Set the list of warnings

Parameters:
Name Type Description
warnings Array.<String>
Inherited From:
Source:
See:

showSteps(dontStore)

Show the steps, as a result of the student asking to show them. If the answers have not been revealed, we should apply the steps penalty.

Parameters:
Name Type Description
dontStore Boolean

don't tell the storage that this is happening - use when loading from storage to avoid callback loops

Inherited From:
Source:

storeAnswer(answer)

Update the stored answer from the student (called when the student changes their answer, but before submitting)

Parameters:
Name Type Description
answer *
Inherited From:
Source:
See:
  • {Numbas.parts.Part.stagedAnswer}

storeTick(answer)

Store the student's choices

Parameters:
Name Type Description
answer Object

object with properties answer and choice, giving the index of the chosen item

Source:

(abstract) studentAnswerAsJME() → {Numbas.jme.token}

Get the student's answer as a JME data type, to be used in error-carried-forward calculations

Returns:
Type Description
Numbas.jme.token
Overrides:
Source:

subCredit(credit, message)

Subtract an absolute value from credit

Parameters:
Name Type Description
credit Number

amount to subtract

message String

message to show in feedback to explain this action

Inherited From:
Source:

submit()

Submit the student's answers to this part - remove warnings. save answer, calculate marks, update scores

Inherited From:
Source: