Trying to Execute JavaScript

So I have an instructor who wants some text inputted and if that text contains either "deep" or "depth" it would be considered correct. I wrote some short JavaScript code to do that, but for some reason it's not even executing. The trigger is set up with the enter button. This is my first time trying to do JavaScript with Storyline, so I have no idea how to really debug this problem.

I've attached the problem slide and pasted my code below.
Please note my "bool" variable is a float. I have it acting like a boolean with the triggers, but wanted a starting point OTHER than True/False or 1/0 so then no matter if it was true or false I knew for sure that variable would change, allowing some of my other triggers to work.

var player = GetPlayer();

var text = player.GetVar("TextEntry");

var deep = text.indexOf("deep");

var depth = text.indexOf("depth");

/* this is just to see if the code is being executed. the -1 on screen should change to a 27 here, but for some reason does not */

player.SetVar("bool", 27);

if (deep > -1) || (depth > -1)

    { player.SetVar("bool", 1) }


    { player.SetVar("bool", 0) };

4 Replies
Kelly Doane

I know this is a very old thread, but I'm wondering if Storyline 3/ or 2019 have made any advancements in this area? 

I'm trying to show/hide certain elements based on a textentry when that textentry contains any part of a word. For example, the 'contains' value might be 'own' where when the learner types owner, ownership, or owns in the text field, the value is seen as true because it contains the value 'own'. 

Unfortunately, I am not versed in Java - but am willing to try if necessary to make this work.