Class: Question

Question

A class to build Questions for Tests configurable and dynamically

Constructor

new Question(parent, conf)

Questions for test

Constructor for creating "Question" objects. It supports a parameter with a configuration object with certain properties or attributes.

Parameters:
Name Type Description
parent Object

"Test" object

conf Object

Configuration object (see conf)

Source:
See:

Members

answers :Array:Answer

Answer objects array

Type:
  • Array:Answer
Source:

conf :Object

Configuration Options

a Javascript object with follow structure:

{
   num: 2,
   nA: 4,
   solution: 0,
   stopOnSuccess : false,
   charset: "utf-8",
   txt: "Question 2 ?"
}
Type:
  • Object
Source:

element :Object:HTMLElement

own DOM element

Type:
  • Object:HTMLElement
Source:

id :string

Exclusive id (+ or -)

Type:
  • string
Source:

intents :number

Counts the intents for this Question

Type:
  • number
Source:

marked :boolean

It keeps track marking for this Question

Type:
  • boolean
Source:

num :number

Number of this Question.

This is not equal to 'this.id' (from 0 to +Infinity)

Type:
  • number
Source:

ok :boolean

Is this question is already succeeded ?

Type:
  • boolean
Source:

parent :Object:Test

"Test" Parent object

Type:
  • Object:Test
Source:

position :number

Position in 'questions' parent array

Type:
  • number
Source:

root :namespaces:testron

"testron" Ancestor object {namespace}

Type:
  • namespaces:testron
Source:

solution :number

clone conf.solution

Type:
  • number
Source:

stopOnSuccess :boolean

clone conf.stopOnSuccess

False = Only one click, True = clicks until success

Type:
  • boolean
Source:

valid :boolean

is valid this Question ?

Type:
  • boolean
Source:

Methods

addAnswer(answer) → {Object:Answer}

Adding an Answer object to this Question

Parameters:
Name Type Description
answer Object:testron.Test.Question.Answer

"Answer" object

Source:
Returns:

Return the same input parameter

Type
Object:Answer

createAnswer(conf) → {Object:Answer}

Create and adding an Answer object to this Test

Parameters:
Name Type Description
conf Object

Configuration object (for Answer Objects)

Source:
Returns:

Return the new Answer created

Type
Object:Answer

emitClick()

Emit the Click event for comprobations in this Question

Source:

emitNext()

Emit the Next event for pass to forward Question

Source:

filterConf(conf) → {Object}

Filter the Configuration Options

The Configuration Options will are get from parent ("Test"), if not exists

Parameters:
Name Type Description
conf Object

Configuration object

Source:
See:
Returns:

The sanitized configuration options

Type
Object

getCounter()

Get the self own-counter

Source:

parseQuestion(test) → {string}

Create questions from 'questions' parameter.

The parameter can be a Javascript object or a JSON string object with follow structure:

questions: [
  {
    conf: {..., txt: "Question 1 ??"},
    answers: [ ... ] // see Question.parseAnswers(...)
  },
  { ... },
  ...
]
Parameters:
Name Type Description
test Object | string

a Javascript object or a JSON string object

Source:
Returns:

a DEBUG string with info

Type
string

remove()

Remove this Test Question (and your children answers)

Source:

removeAnswers()

Remove all answers for this Test Question

Source:

sanitizeAnswers()

Remove the invalid answers

Source:

toFail()

Change the style to FAIL for this Question DOMElement

Source:

toHtml() → {Object:HTMLElement}

Create the HTML-UI for this Question and return it as HTMLElement (HTMLUlElement)

Source:
Returns:
Type
Object:HTMLElement

toJSON() → {string}

Parse this element to JSON

Source:
Returns:

a JSON string which represents to this Question object

Type
string

toOK()

This changes the style for this Question DOMElement. Also shoots the 'emitNext' event

Source:

update_nA()

Updates the answers number

Source:

verify() → {boolean}

This checks the solution for this Question

Source:
Returns:

True / False

Type
boolean

based on the 'Doctron template'   by
Δ