javascript to round a calculation result
Oct 18, 2016
I am using triggers to generate an output numeric value (Viscosity) based on an input numeric value and a calculation. The calculation works great, but I would like the output to be rounded to the nearest whole number. I have added a javascript trigger with the code below. I won't know if it works until the module has been uploaded to the LMS, but I'm not even sure I have the right java code. I have pieced this together based on Articulate best practices and W3. Can someone tell me if this looks right?
var Viscosity = Math.round ()
Trigger is...
Action: Execute JavaScript
Script... (this is where I entered the code above)
When: User clicks
Object: Button 3
No conditions.
"Viscosity" is the name of the numeric variable that I would like rounded to the nearest whole number.
Thanks~
4 Replies
Hello Sue,
Here is the javascript that you will need. I have also attached a sample project.
var lmsAPI = parent;
var player=GetPlayer();
var RoundedViscosity = player.GetVar("Viscosity");
RoundedViscosity = Math.round(RoundedViscosity);
player.SetVar("Viscosity", RoundedViscosity);
Wow, this is great, thank you so much!!!
After trying various work arounds, I found your method with Java Script. Didn't know it could be so easy! Thanks so much
Glad to see that this is still helping out. Thanks for popping in to share Tony :)
Welcome to E-Learning Heroes!
This discussion is closed. You can start a new discussion or contact Articulate Support.