You could try a JavaScript that uses the remainder ("%") operator. Something like:

var player = GetPlayer(); var JSValue1 = player.GetVar("Value1"); var JSValue2 = player.GetVar("Value2"); var JSResultTemp = JSValue1 / JSValue2 var JSResult = Math.floor(JSResultTemp); var JSRemainder = JSValue1 % JSValue2; player.SetVar("Result",JSResult); player.SetVar("Remainder",JSRemainder);

With the script snippet I had shown earlier, the Remainder would be passed into a Storyline variable, which you can then display. See attached the example file and here is the published version.

Thanks Owen. I thought there should be a way to do this without JavaScript. I've used Java in other lessons, but I'm not entirely confident in it yet and I like the ability to test it in preview mode rather than publishing it each time I make a change to test it.

@Owen: That's a nice one, thanks for sharing! I always tend to go for JavaScript first when it comes to math-related questions. You changed my mind, from now on I'll go for triggers first, even if it takes a few more!

The key is to take it one simple step at a time. I knew that if I could isolate the whole number portion, subtracting it from the numerator to get the remainder would be the easy part.

## 9 Replies

You could try a JavaScript that uses the remainder ("%") operator. Something like:

var player = GetPlayer();

var JSValue1 = player.GetVar("Value1");

var JSValue2 = player.GetVar("Value2");

var JSResultTemp = JSValue1 / JSValue2

var JSResult = Math.floor(JSResultTemp);

var JSRemainder = JSValue1 % JSValue2;

player.SetVar("Result",JSResult);

player.SetVar("Remainder",JSRemainder);

Thanks Michael,

Is there a way to show the Remainder? I know with variables I can use %variable% reference but I'm not sure how to show the remainder on the screen.

With the script snippet I had shown earlier, the Remainder would be passed into a Storyline variable, which you can then display. See attached the example file and here is the published version.

remainderjs_mh.storyCool, that worked.

Interested in a non java solution?

As long as your numerator is greater than your denominator....

Variables required: Numerator, Denominator, Answer, CalculateRemainder, Remainder.

Set your Answer = to the denominator

Subtract 0.49 from the Answer

divide your Answer by 10000000

multiply your Answer by 10000000

This gives you the whole number portion of your solution stored in the variable Ă„nswer".

Set an additional variable (I called mine CalculateRemainder) = to your Denominator

multiply this by your Answer.

Set your Remainder = to the Numerator

Subtract your additional variable from your remainder.

This gives you the remainder portion of your solution stored in a variable called Remainder.

remainder.storyThanks Owen. I thought there should be a way to do this without JavaScript. I've used Java in other lessons, but I'm not entirely confident in it yet and I like the ability to test it in preview mode rather than publishing it each time I make a change to test it.

No problem. Let me know if you have any questions about the file I attached or the logic.

@Owen: That's a nice one, thanks for sharing! I always tend to go for JavaScript first when it comes to math-related questions. You changed my mind, from now on I'll go for triggers first, even if it takes a few more!

The key is to take it one simple step at a time. I knew that if I could isolate the whole number portion, subtracting it from the numerator to get the remainder would be the easy part.

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