Using Javascript to get question text

Jun 19, 2016

Hi All, 

I developed a quiz that has a question bank of 42 questions. The questions are random and the learner has 10 minutes to complete as many questions as they can. The client wants me to show the learner what questions they missed and also pass that info to the LMS for managers on the backend to view. I created a variable for each question with the question text and when the question is answered correctly, using a trigger, I have that text removed from the variable so its blank. At the end, I want to collect all the questions that were answered incorrectly pass them to the LMS. From what I've read so far in the discussions, I need to use Javascript, but I'm new to that and Storyline2 as well. Any help would be most appreciated! Also, you should know, because of how the client wants me to score them, I can't use the built-in results slide - I had to calculate each score separately and mark them wrong or right using triggers instead. 

Thanks, 
Eric

5 Replies
Christie Pollick

Hi, Eric -- Thanks for your question and welcome to the community! You may not be aware, but JavaScript is an area where we are not able to offer support, so we'll need to defer to the JS gurus in the community to assist you further. I did, however, want to pass along this document on JS Best Practices and Examples that you may want to review, as well. 

Eric Markowitz

A developer from this site - Stephen Gerbrandt helped me out. He had created a dynamic bulleted list (here: https://community.articulate.com/discussions/articulate-storyline/need-a-bulleted-numbered-list-to-update-dynamically-based-on-user-input). His JS solution for me is below. It runs/triggers when the user clicks to view their incorrect questions. On each question, if the user gets it wrong, it places the question text into a variable QxTextView, where "x" is the number of the question. Hope this helps others:

var player = GetPlayer();

var questionSummary = player.GetVar("questionSummary");

var totalQuestionCount = 42;  //enter your total question count, this number could, possibly, be determined more dynamically so it can handle any number of questions without you having to update it

var currQuestionNum = 1; //the current question number we are adding to the list

var currQuestionVal =""; //defining variables outside of a for loop makes JS happy and avoids scope issues and needless re-creation of values

var tempSummary = "";

for (; currQuestionNum <= totalQuestionCount; currQuestionNum++) {

//since all of your variables follow the same pattern we can generate the name like this by concatenating the string together

currQuestionVal = player.GetVar("Q" + currQuestionNum + "TextView");

if (currQuestionVal !== "") {
    tempSummary += "\u2022 " + currQuestionVal + "\n";
    tempSummary += (currQuestionVal < totalQuestionCount) ? "\n" : ""; //if it's our last question don't add a new line to the end
    }
}

player.SetVar("questionSummary", tempSummary);

 

This discussion is closed. You can start a new discussion or contact Articulate Support.