Forum Discussion
Text entry variables and xAPI
I'm liking the idea of one statement at the end because it's too easy to have a typo in 130 different statements. Thank you for the code.
Right now I'm using the question name (e.g., Comment_Mary1, Comment_Mary2, Comment_Mark1) as the comment name. The questions are named not numbered because we are pulling from a test bank (learner confused if they get questions 37, 45, 63?).
If I rename all the comments 1, 2, 3, and pull them in a list at the end, how will I know which comment refers to what question?
Now it’s getting more complicated. The script above assumes a specific pattern and stores comments based on their index number. However, I see that your comment variables follow a different, more complex pattern, which seems harder to target. I’m concerned I might lose control over this as it becomes more dynamic. Here is updated script that we can try to target all comments based on your pattern:
var totalVars = 130;
var people = ["Mary", "Mark"];
var responses = [];
for (var p = 0; p < people.length; p++) {
var person = people[p];
for (var i = 1; i <= totalVars; i++) {
var varName = "Comment_" + person + i;
var varValue = getVar(varName);
if (varValue && varValue.trim() !== "") {
responses.push(varName + ": " + varValue);
}
}
}
var jointResponse = responses.join(" | ");
setVar("xapiResponse", jointResponse);
console.log("xapiResponse set to:", jointResponse);
This way, you can add as many names as needed to the 'people' array variable. For example, if you have variables like Comment_John1, Comment_John2, etc., the 'people' variable should be updated to ["Mary", "Mark", "John"]. Again, all variables need to follow the same pattern for this to work properly. In this case, you would not have to rename your variables. If your question name is Comment_Mary1 it will show in the statement followed by response. With this update, my xapiResponse statement would appear as:
Related Content
- 12 months ago
- 8 months ago
- 10 years ago