"cmi5 allowed" Statement methods
The optional "cmi5 allowed" statement methods for communicating module status.
progress
Sends the learner's progress for the AU.
Example
import Cmi5 from "@xapi/cmi5";
const cmi5 = new Cmi5();
// initialize etc
cmi5.progress(50);
Parameters
Parameter
Type
Required
Description
percent
number
true
The learners progress of the AU as a percentage.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionTrueFalse
Sends the learner's boolean based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { LanguageMap } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "is-true-true";
const answer = true;
const correctAnswer = true;
const success = answer === correctAnswer;
const name: LanguageMap = {
"en-US": "Is True True"
};
const description: LanguageMap = {
"en-US": "In a boolean context, is true truthy?"
};
cmi5.interactionTrueFalse(testId, questionId, answer, correctAnswer, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answer
boolean
true
The answer supplied by the learner.
correctAnswer
boolean
false
The correct answer decided by the learning designer.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionChoice
Sends the learner's choice based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { LanguageMap, InteractionComponent } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "first-two-choices";
const answerIds: string[] = ["choice1", "choice4"];
const correctAnswerIds: string[] = ["choice1", "choice2"];
const success = false;
const choices: InteractionComponent[] = [{
id: "choice1",
description: {
"en-US": "Choice 1"
}
},
{
id: "choice2",
description: {
"en-US": "Choice 2"
}
},
{
id: "choice3",
description: {
"en-US": "Choice 3"
}
},
{
id: "choice4",
description: {
"en-US": "Choice 4"
}
}];
const name: LanguageMap = {
"en-US": "First Two Choices"
};
const description: LanguageMap = {
"en-US": "What are the first two choices?"
};
cmi5.interactionChoice(testId, questionId, answerIds, correctAnswerIds, choices, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answerIds
string[]
true
The Id(s) of the answer(s) supplied by the learner.
correctAnswerIds
string[]
false
The correct Id(s) of the answer(s) decided by the learning designer.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionFillIn
Sends the learner's short text based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { LanguageMap } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "hello";
const answers = ["whos there?"];
const correctAnswers = ["world", "World"];
const success = false;
const name: LanguageMap = {
"en-US": "Hello"
};
const description: LanguageMap = {
"en-US": "Hello?"
};
cmi5.interactionFillIn(testId, questionId, answers, correctAnswers, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answers
string[]
true
The answer(s) to the question.
correctAnswers
string[]
false
The correct possible answer(s) to the question.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionLongFillIn
Sends the learner's long text based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { LanguageMap } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "hello-long";
const answers = ["whos there?"];
const correctAnswers = ["world", "World"];
const success = false;
const name: LanguageMap = {
"en-US": "Hello"
};
const description: LanguageMap = {
"en-US": "Hello?"
};
cmi5.interactionFillIn(testId, questionId, answers, correctAnswers, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answers
string[]
true
The answer(s) to the question.
correctAnswers
string[]
false
The correct possible answer(s) to the question.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionLikert
Sends the learner's Likert based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { InteractionComponent } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "highest-value";
const answerId = "likert4";
const correctAnswerId = "likert4";
const scale: InteractionComponent[] = [{
id: "likert0",
description: {
"en-US": "Very Unsatisfied"
}
},
{
id: "likert1",
description: {
"en-US": "Unsatisfied"
}
},
{
id: "likert2",
description: {
"en-US": "Neutral"
}
},
{
id: "likert3",
description: {
"en-US": "Satisfied"
}
},
{
id: "likert4",
description: {
"en-US": "Very Satisfied"
}
}];
const name: LanguageMap = {
"en-US": "Highest Value"
};
const description: LanguageMap = {
"en-US": "What is the highest value on this scale?"
};
cmi5.interactionLikert(testId, questionId, answerId, correctAnswerId, scale, name, description)
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answerId
string
true
The Id of the answer supplied by the learner.
correctAnswerId
string
false
The correct Id of the answer decided by the learning designer.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionMatching
Sends the learner's matching based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { LanguageMap, InteractionComponent } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "food-groups";
const answers = {
apple: "fruit",
carrot: "vegetable"
};
const correctAnswers = {
apple: "fruit",
carrot: "vegetable"
};
const success = true;
const source: InteractionComponent[] = [{
id: "apple",
description: {
"en-US": "Apple"
}
}, {
id: "carrot",
description: {
"en-US": "Carrot"
}
}];
const target: InteractionComponent[] = [{
id: "fruit",
description: {
"en-US": "Fruit"
}
},
{
id: "vegetable",
description: {
"en-US": "Vegetable"
}
}];
const name: LanguageMap = {
"en-US": "Food Groups"
};
const description: LanguageMap = {
"en-US": "Match the food items to their groups."
};
cmi5.interactionMatching(testId, questionId, answers, correctAnswers, source, target, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answers
{[key: string]: string}
true
The source-target key-value pairings of the answers supplied by the learner.
correctAnswers
{[key: string]: string}
false
The correct source-target key-value pairings of the answers decided by the learning designer.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionPerformance
Sends the learner's performance based answer to an interaction.
Example
import Cmi5, { Performance, PerformanceCriteria } from "@xapi/cmi5";
import { LanguageMap } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "trex-runner";
const answers: Performance = {
distance: 500
};
const correctAnswers: PerformanceCriteria[] = [{
id: "distance",
min: 100
}];
const success = true;
const name: LanguageMap = {
"en-US": "T-Rex Runner"
};
const description: LanguageMap = {
"en-US": "Get a score of minimum 100 on T-Rex Runner"
};
cmi5.interactionPerformance(testId, questionId, answers, correctAnswers, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
correctAnswers
false
The correct source-target key-value pairings of the answers decided by the learning designer.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionSequencing
Sends the learner's sequence based answer to an interaction.
Example
import Cmi5 from "@xapi/cmi5";
import { LanguageMap, InteractionComponent } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "number-order";
const answerIds: string[] = ["one", "three", "two", "four"];
const correctAnswerIds: string[] = ["one", "two", "three", "four"];
const choices = InteractionComponent[] = [{
id: "one",
description: {
"en-US": "One"
}
},
{
id: "two",
description: {
"en-US": "Two"
}
},
{
id: "three",
description: {
"en-US": "Three"
}
},
{
id: "four",
description: {
"en-US": "Four"
}
}];
const success = false;
const name: LanguageMap = {
"en-US": "Number Order"
};
const description: LanguageMap = {
"en-US": "Put the numbers in order"
};
cmi5.interactionSequencing(testId, questionId, answerIds, correctAnswerIds, choices, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answerIds
string[]
true
The Id sequence of the answers supplied by the learner.
correctAnswerIds
string[]
false
The correct Id sequence of the answers decided by the learning designer.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionNumeric
Sends the learner's numeric based answer to an interaction.
Example
import Cmi5, { NumericCriteria } from "@xapi/cmi5";
import { LanguageMap } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "human-legs";
const answer = 2;
const correctAnswer: NumericCriteria = {
exact: 2
};
const success = true;
const name: LanguageMap = {
"en-US": "Human Legs"
};
const description: LanguageMap = {
"en-US": "How many legs does a human have?"
};
cmi5.interactionNumeric(testId, questionId, answer, correctAnswer, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answer
number
true
The answer supplied by the learner.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
interactionOther
Sends the learner's "other" based answer to an interaction.
Example
import Cmi5, { NumericCriteria } from "@xapi/cmi5";
import { LanguageMap } from "@xapi/xapi";
const cmi5 = new Cmi5();
const testId = "test1";
const questionId = "plymouth-location";
const answer = "(53.756898, -4.501819)";
const correctAnswer = "(53.756898, -4.501819)";
const success = true;
const name: LanguageMap = {
"en-US": "Plymouth Location"
};
const description: LanguageMap = {
"en-US": "On this map, please mark Plymouth, Devon"
};
cmi5.interactionOther(testId, questionId, answer, correctAnswer, name, description, success);
Parameters
Parameter
Type
Required
Description
testId
string
true
The identifier of the test.
questionId
string
true
The identifier of the question.
answer
string
true
The answer to the question.
correctAnswer
string
false
The correct possible answer to the question.
success
boolean
false
Whether the learner interaction result was a success or not.
Returns
This returns a Promise
containing an array with the resulting statementId if successful.
Last updated
Was this helpful?