Word count

May 11, 2015

I have a course that is setup for data entry. The user has to shorten the given sentence. I know the length of hte given sentence, but the user's sentence I do not know. Is there a way in Storyline to count the number of words in the data entry box and divide that by the original word to give a percentage? For eample, if the original word count is 35. and the user word count is 29, there is a 17% reduction in the word count.  The data entry is assigned to a variable.

4 Replies
Nancy Woinoski

You will have to use JavaScript for this.

I created a similar exercise once in which I wanted the user to reduce a paragraph from 85 words to 33 words. My solution does not calculate a percentage but does give you the user's actual word count.

I created a text input field and assigned it a variable name called EssayText2 - I placed the 85 words in the default value field for the variable.

I added a custom button and added a trigger to execute this JavaScript when clicked.

var player = GetPlayer();
var EssayText2 = player.GetVar("EssayText2");
var EssayText2 = EssayText2 + " "; 
var initial_whitespace_rExp = /^[^A-Za-z0-9.']+/gi;
var left_trimmedStr = EssayText2.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9.']+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var WordCount = splitString.length -1;
player.SetVar("WordCount", WordCount);

 

Note: the word count that the user achieved is stored in a numeric variable I created called WordCount - you will need to add %WordCount% on your slide to display the count the user achieved.

Also note: this used to work on all browers but I have not tested it in a while.

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