Formula Based Questions

Oct 17, 2012

Hi Everyone

Thought I would share a new type of question with the community.

Thanks to Jeanette and her great tutorial on evaluating more than one text entry areas by using a freeform pick one question, I was inspired to create a question where I could randomly generate 3 variable numbers then evaluate the students answer verses the correct answer.

The formula for the electrical calculation is Rt = 1/((1/R1)+(1/R2))

which gives the parallel resistance. Then Volts/Rt = current (amps)

You can view the javascript for the random variables on the untitled layer 3

var V1 = Math.floor(Math.random() * (5000 - 3000 + 1)) + 3000;

Math.floor is used to give a better randomization. Math.random() gives a number between 0 and 1. In this example 5000 is the max value 3000 is the min value (min value is used in 2 places in the formula)

I have then worked thru the formula in separate stages as it didn't want to work in a single line.

The result of the formula is then rounded.

var result=Math.round(V4*1000)/1000;

in this example I am rounding to 3 decimal places. 100 instead of 1000 would round to 2 decimal places, 10000 instead of 1000 would round to 4 decimal places

I have then set the value of the appropriate variables in the storyline player.

I have then set the state of the hidden buttons by evaluating the variable Answer1 and the TextEntry field.

Couple of things I have discovered:

  1. Number Entry fields automatically round to 2 decimal places (not always helpful, so use the Text Entry field if you want it to be as it is written wich means your Answer variable must be a text field too.)
  2. The Javascript doesnt seem to trigger from the Timeline Start event so I added the untitled layer 3 and triggered the event from the continue button.
  3. You need to carefully consider where things are in the timeline and where they are stacked in the Triggers list otherwise you will leave a page or a state before you have completed all of the actions.

Have fun with the example tear it apart if you can improve it share your results

Regards Graeme

1 Reply

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