Using Java Script to identify what has been typed in a free text box in an assessment question

Hi,

I am currently building an assessment for the end of one of my  courses and one of the questions requires a free text box where the user can type in their answer to the question. The user has two attempts to get the answer correct by typing in the correct list of objects. I was wondering how you would use Java Script to recognise whether the user has typed in the correct words?

For example if the question was; Name four farm animals.

Answer: Pig, cow, chicken, sheep.

If the user typed in Pig, cow, dolphin, unicorn, I want storyline to be able to recognise what they have typed and to know that they got two correct but two wrong so need to try again.

Sorry if that makes little sense! I am getting confused trying to explain it.

If any one has any advice it would be much appreciated.

PS I am not new to Storyline but I am new to Java Script so have no idea how to use it.

12 Replies
Rebecca Carter

Hi Matthew,

As I am completely new to Java I have no idea how to start this tutorial off, I have done the the initial part by creating a text entry box and submit button and converted the slide to freeform text entry etc etc. Now I am on the first of your instructions which is; The first step is to establish communication with storyline:

var player = getPlayer ();

It may be something really obvious but I don't know what to do with this, do I copy and paste it into the 'Execute JavaScript' script section of the variable wizard?

Is this the first line of code?

And the 2nd instruction I am really confused by, do I need to create a new text variable? then fill it with the text that is stored in storylines 'textentry' variable? I have no idea what this means....

Apologies it would appear that I am completely clueless!

thanks,

Rebecca

 

Matthew Bibby

No need to apologise, I know how confusing this stuff can be when you haven't used JavaScript before. I'm sorry that the tutorial isn't clearer!

You've got the right idea, you need to copy that code into the Execute JavaScript section. 

You may find it helpful to download the source file that comes with the tutorial and have a look at how that is set up.

JavaScript has variables and Storyline has variables. And because we want to do stuff with JavaScript, we have to copy the information from the Storyline variable to the JavaScript variable.

So with the second instruction, we are creating a new JavaScript variable (which we do by typing var text) and then we are going to take the value of the Storyline variable TextEntry and add that to the JavaScript variable. 

You should have a Storyline called TextEntry in your course already, it is created when you add a text entry field. 

Does that help? Or have I confused you more?

Edit: A JavaScript variable doesn't exist in Storyline at all. It only exists in the JavaScript.

Rebecca Carter

Hi Matthew,

I think this helps! Thank you. When I try to download the source file it just takes me to the tutorial rather than downloading a file?

One more thing, at the end when you say you need to create a 'Points' variable, what kind of variable is this?

You tutorial is really good so no need to worry there, I just got very confused with the use of the word variable!

Thank you for your help and wisdom!

Rebecca Carter

Hi Matthew,

I have been trying to get my head around this all day and I don't think this example is actually what I need to do. I don't want my users to score points when they type the correct words, I want them to be able to type freely into the box to answer the question and when they submit if they have most of the correct words or phrases typed in the box then they are shown the 'correct' feedback slide.

If they don't type enough correct words or phrases I when they submit I want them to be shown the 'try again' feedback slide etc etc.

If they still don't get it right then they will be shown the 'incorrect' feedback slide and shown the correct selection of possible answers.

Do you know anywhere I would be able to watch a tutorial on how to do this? I can't find anything in youtube for storyline with Javascript for this purpose. Or are there any written tutorials for this that you know of? Also the fact that Storyline doesn't allow you to preview the slide to see if the JavaScript has worked is not helpful :( 

thank you,

Rebecca

 

Matthew Bibby

Hi Rebecca,

This code can be modified to do what you want. 

If you'd like to provide some additional detail, I can put together a demo for you when I have a spare few minutes sometime over the next day or two.

I'd need to know what the correct words are, how many correct words you want them to enter and so on. You can either post that information publicly here or email me directly. If you've got a source file you'd like it integrated into, feel free to provide that as well.

Thanks.