FILL IN THE BLANK - evaluate answer
Dec 20, 2018
I have a FILL IN THE BLANK question where the accepted answer is:
TO PREVENT PLUGGING
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
Hi,
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 = str.search("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
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.
Here you go!
var player = GetPlayer();
var str = player.GetVar("TextEntry");
var n = str.indexOf("plug");
if(n != -1){
player.SetVar("isFound", "True");
}else{
player.SetVar("isFound", "False");
}
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 = str.search("plug");
if(n > 0){
player.SetVar("TextEntry", "TO PREVENT PLUGGING");
}else{
player.SetVar("TextEntry", str);
}
Actually it IS working if I press the SUBMIT button.
It isn't working when we press the ENTER key, trying to get the logic steps working for that, too.
So I ended up
https://360.articulate.com/review/content/9e0d2e6f-f608-4af3-a8f9-087d0b787005/review
It's working on the review portal, question #5.
Thanks for the assist!
You can also try this method
var player = GetPlayer();
var str = player.GetVar("TextEntry");
//var n = str.indexOf("plug");
var keyword_found = str.match(/plug/g);
alert(keyword_found);
You will get as many "plug" keyword from the input if any.
This discussion is closed. You can start a new discussion or contact Articulate Support.