Rounding the results of a quiz in Articulate Storyline 360

There may be a requirement to round the results of the quiz so as to display a full number and not a number with a decimal place. For example, show 91% instead of 90.89%.

This can be achieved by adding some custom JavaScript to a trigger using the Math.round functionality.

The first step is to create a new variable that will hold the Results.ScorePercent. For this example, a variable named MyResults has been created with a type of Number. This is important, as the custom JavaScript that is used is looking for a Number. If the type is set to Text, the results of the rounding may not work.

In the trigger, set the Variable to equal the system variable of yourresultspage.ScorePercentage and insure the When is set to Timeline Starts. Immediately after this trigger, add another trigger that will execute JavaScript. It must happen after the setting of the system variable as we need to use it.


Click on the 3 dots beside the Script and enter the following code:

var player = GetPlayer();
var tempResults = Math.round(player.GetVar("MyResults"));
player.SetVar("MyResults",tempResults);      

This code will take the actual value that was put into the MyResults variable and put it in a temporary variable where the rounding will occur. The rounded value is then put back into MyResults variable. Now that the correctly rounded results are in our variable, we can display the contents of the variable on the results page. This is achieved by adding a text box and wrapping the variable in %.

That’s it!

1 thought on “Rounding the results of a quiz in Articulate Storyline 360

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.