Forum Discussion
Javascript - script to update text not working
Hi - I'm trying to set a feedback layer to a multiple choice question to display different text depending on which answers are given (the user can select more than one answer)
So if they select wrong answer 1 - it adds feedback 1
If they select wrong answer 2 - it adds feedback 2
If they select wrong answer 3 - it adds feedback 3
so, for example, selecting wrong answers 1 & 3 gets feedback 1 & 3, skipping out 2.
____
I'm using Javascript to add the feedback, executing if they've selected a given response. The variable to check which response they've given is being used elsewhere on screen and working well, so I think the problem must be in my Javascript.
var player = GetPlayer();
var newfeedback = player.GetVar("feedback1pt7") + "Feedback Text 1<br/><br/>";
player.SetVar("feedback1pt7", newfeedback);
I used this project as the basis: https://community.articulate.com/discussions/articulate-storyline/append-text-to-an-existing-text-variable
Thanks!
- MatthewCaisleyCommunity Member
Update: I've added
console.log("working");
in a few places to check. Everywhere I do this, the console gives me the following message:
"ds-bootstrap.min.js:11 actionator::exeJavaScript - this.execUserJs is not a function" - PhilMayorSuper Hero
Are you testing online?
Code looks OK, I wonder if you have other JS that is broken or if the variable are not defined in storyline or you have a typo
- MatthewCaisleyCommunity Member
Hi Phil, thanks for following up. The variables are all defined (we're using them elsewhere without issue), but i wouldn't put it past me to have some incorrect JS somewhere else in the project.
Would having other JS in the project that doesn't work break the JS everywhere? A bit new to this side of articulate.
- PhilMayorSuper Hero
All the JS in storyline is stored in one file user.js and one error can bomb everything
- MatthewCaisleyCommunity Member
Good to know! I removed everything but the JS I refered to above and that's resolved the issue. Thanks very much.