JavaScript in Storyline 360: Add/Remove List Answers

There's no native way that I can find to add an input management list in Storyline 360 so I've created a custom way to do it with JavaScript. First create a project then add two data input boxes, one for user input and another for the answer list and an Add button. It should look something similar to the screenshot below.

Change the variable value being set by the answer input box to "answer" and the answer list to "answerDisplay". Then add a new variable called "answerList".

Now create a trigger that will change the data type of answerList to an array at the start of the slide.

const player = GetPlayer();

player.SetVar("answerList", []);
Click to copy

Next, add a JavaScript trigger to the button that adds the typed answer to the answer list when clicked.

const player = GetPlayer(); // Player reference

const answerList = player.GetVar("answerList"); // Assign answerList value to local variable
const answer = player.GetVar("answer"); // Get the value of answer
let answerDisplay = "";

answerList.push(answer); // Add answer value to answerList

for(let i=0; i<answerList.length; i++){ // Loops through the list of answers
    answerDisplay += answerList[i]+"\n"; // Appends the answer to answerDisplay separated by new line
}

player.SetVar("answerList", answerList); // Update the answerList project variable value
player.SetVar("answerDisplay", answerDisplay); // Update the answerDisplay project variable value
Click to copy

Then clear the answer input field with a trigger when the Add answer button is clicked.

Now we add the the remove function to the answer list input box. Create a JavaScript trigger for answer list that triggers when it loses focus and add the code below.

const player = GetPlayer(); // Player reference

let answerDisplay = player.GetVar("answerDisplay"); // Get answerDisplay value

let answerList = answerDisplay.split("\n"); // Creates a list of answers
answerDisplay = "";

for(let i=0;i<answerList.length;){ // Loops through the list
    if(answerList[i] == ""){ // Checks if list has empty value
        answerList.splice(i, 1); // Remove answer in list
    }else{
        answerDisplay += answerList[i]+"\n"; // Appends the answer to answerDisplay
        i++; // Increment index
    }
}

player.SetVar("answerList", answerList); // Update the value of answerList
player.SetVar("answerDisplay", answerDisplay); // Update the value of answerDisplay
Click to copy

You now have a modifiable list. To update the answer list, edit it directly in the answer list input box.