Javascript for state change based on variable percentage...

Mar 07, 2013

Hi there,

I'm looking to have a state change on an object (status) based on two variables (score and total). Because there are a number of questions in the lesson, the range of scores makes using simple triggers a headache (score is equal to, less than X, show this, score is less than Y, show this, etc.). Basically I would need a ton of them.

If I was able to have a state change based on current score and it's percentage of the current total, this would take care of that.


state change on object A

to "Doing Great!"

when timeline starts

if variable x is 50% of variable y

Is this possible with javascript? If so, any pointers on the code?



4 Replies
Alexandros Anoyatis

Hi Nathan,

You could do that with javascript (I guess), but why not take advantage of the master slide for this?

Instead of repeating your triggers in every slide, just create a new layout in your Slide master, create the variable logic once and use that for the duration of your question slides.

Hope this helps,

Nathan Blesse

I am using one central slide as a menu/home slide that contains the users score and total, etc. So it essentially serves the same purpose as the master slide. I only need to create the triggers on that slide.The user selects scenarios to visit from this slide, in any order they like. After completing each scenario they return to the home screen and will see their score and a status based on their score in relation to the total points currently possible.

After just one scenario, the triggers would be minimal based on only a few possible score/total combos. After three, four or five scenarios it would require more triggers based on increasing possible score/total combinations. I can certainly figure out all possibilities, but the percentage would simplify this greatly.

My issue is not wanting to put 12-15 triggers on a slide when a simple equation could sum it up in one trigger.

Hopefully that makes sense.



Alexandros Anoyatis

If you only have to calculate the percentage when the timeline of your home slide starts, then something like what I have set up in the attached file may be enough.

A quick explanation of the variables :
score : is the total score your learned has achieved so far
maxscore : total maximum score so far
grade : individual section score
activesection : just a marker so the section cannot be attempted again
howaretheydoing : a temporary number that (after a sequence of triggers) becomes the actual value we check against to display the appropriate TextBox2 state

Hope that drives you to the right direction.

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