FILL IN THE BLANK - evaluate answer

I have a FILL IN THE BLANK question where the accepted answer is: 

I'm trying to come up with a list of all the possible variations students could come up with and still be correct, tedious.  And I could easily miss a variation, I can see a complaint coming at some point in the future.

What I'd like to do is evaluate the answer they give to simply see if the word "plug" is in the answer, then accept it as correct if it is.

Can we do that with some sort of javascript?

7 Replies
Daniel Servan


You can use Javascript to search for the word "plug"

You can do like this.

var str = "There is a plug in here...";
var n ="plug");

alert(n);// n is equal to 11, if n =  -1 then a word plug not found

You can also use indexOf() function
var str = "There is a plug in here...";
var n = str.indexOf("plug");

alert(n);// n is equal to 11, if -1 then a word plug not found



Jerry Beaucaire

So execute script when textentry loses focus.

Then get the value of VAR N using your code.  

Then some sort of IF THEN so if var N > 0 then change the value of the textentry box to "TO PREVENT PLUGGING" which is the #1 acceptable answer.

Trying to think all this through.

Jerry Beaucaire

Hmm, when I publish this slide to test, nothing happens, the TextEntry value never changes.

Here;s my final script:

var player = GetPlayer();

var str = player.GetVar("TextEntry");
var n ="plug");

if(n > 0){
player.SetVar("TextEntry", "TO PREVENT PLUGGING");
player.SetVar("TextEntry", str);

Jerry Beaucaire

So I ended up

  1. abandoning the FILL IN THE BLANK
  2. switching to a TRUE/FALSE with the options hidden from user's view
  3. adding a layer with a text input box large enough for three lines that appears first to the user, the text box is already selected and blinking this way
  4. I used the javascript to evaluate the input box string and if the word "plug" is there, I changed whatever they entered to TO PREVENT PLUGGING
  5. use triggers to evaluate the text now, if it says TO PREVENT PLUGGING, set the hidden options to TRUE and submit.
  6. If it says anything else, set the hidden options to FALSE and submit. 

It's working on the review portal, question #5.

Thanks for the assist!