Javascript syntax for variables (if var == 1 then add var "a" to var "result")

Mar 04, 2016

Hi all,

I saw this earlier thread and I’m trying to do something similar for an Assessment im working on.

https://community.articulate.com/discussions/articulate-storyline/variables-adding-numbers-or-text#reply-338575

There are 6 questions after each question you get feedback, if you get the answer incorrect you get text to say which section in the course to look at. So for example get Question 1 incorrect, "look at section 1", get Question 2 incorrect, "look at section 2" and so on. A the results I want to list the sections that the user needs to review in a text box, so for example the user gets Questions 1, 2  and 5 incorrect the list would be:

look at section 1

look at section 2

look at section 5

I have tried to do this with Javascript execute but can't get it to work from the example here:

If (Q1Incorrect == 1) {

var Q1 = "look at section 1";

}

if (Q2Incorrect == 1) {

var Q2 = "look at section 2";

}

if (Q1Incorrect == 1) {

var Q3 = "look at section 3";

}

var list= Q1+"\n"+Q2+"\n+Q3+"\n;
player.SetVar("sections",list);

Having no luck, any help much appreciated, I have included a story file to show the concept.

Haydn

4 Replies
Haydn Howard

Here's the working file, may be of use to someone :)

I've solved it below:

var e = player.GetVar("AssSect1");
var f = player.GetVar("AssSect2");
var g = player.GetVar("AssSect3");

var res= player.GetVar("Result");
var str1= player.GetVar("ResSect1a");
var str2= player.GetVar("ResSect2a");
var str3= player.GetVar("ResSect3a");

if (e == 1) {
var str1= a+"\n";
var res = res+str1;
}

if (f == 1) {
var str2= b+"\n";
var res = res+str2;
}

if (g == 1) {
var str3= c+"\n";
var res = res+str3;
}

player.SetVar("sections1", res);

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