looking for a way to find a word or phrase with in a text box reponse

Mar 10, 2015

Hello all.. I am admitting I am stumped. I have been trying to write some kind of code that will allow me to look for a phrase within a text answer and then set the layer to correct if it finds that phrase..  here is my code if it helps. TextEntry1 is the textbox where the answer is and is stored when the control looses focus (per the trigger).

var player = GetPlayer();
var anwser1 = player.GetVar("TextEntry1");

var untrue = "false"

var test = "true"

 switch(anwser1)
{
case "bob"
   player.SetVar("correctanwser",test);
   break;
case "frog"
   player.SetVar("correctanwser",test);
   break;
case "test"
   player.SetVar("correctanwser",test);
   break;
default
   player.SetVar("correctanwser",untrue);
}

alert(player.GetVar("correctanwser"));

 

6 Replies
Michael Hinze

I had done something similar a long time ago. Here is an example: http://dev.keypointlearn.com/xcl71_SL/TEBContains/ 

This script snippet here:

"var player = GetPlayer();
var rawString =player.GetVar("TextEntry");
var TEBcontains="false";
var searchString=rawString.toLowerCase();
if (searchString.match ("good") || searchString.match ("great") || searchString.match ("creative") || searchString.match ("awesome") || searchString.match ("interesting")) TEBcontains="true";
player.SetVar("Result",TEBcontains);"

searches a textentry variable for keywords like 'good', 'awesome' etc. and displays content based on that search. Seems like a simpler script than the one you are trying?

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