Forum Discussion
ShannonConnor
4 years agoCommunity Member
Add square and square root buttons to an existing Javascript calculator built in SL 360
Hello! A few years ago I obtained a wonderful calculator from a fellow user on this forum. I now need to add a square button and square route button. I am not fluent with Javascript. I have attached...
MathNotermans-9
4 years agoCommunity Member
Ah yes, my mistake on the square function. Right...
Change indeed the var calculation to 'q'
player.SetVar("calculation", "q");
And then on the = use Math.pow when calculation = q
As Math.pow uses 2 input values Math.pow(2,2) you can add a variable to use as the power number. Im not sure how that works in regular calculators but in some way you should be able to calculate the power of 2,3 etc. etc.
Adding power as a variable in Storyline. Set to 2 for now.
And then i added:var mypower = player.GetVar("power");
} else if (mycalc == "q") {
mysum = Math.pow(mysum, mypower);
And here it is complete.
If you want to change the power of 2 to the power of 3,4 or whatever... change the variable power in Storyline and that works too.
Kind regards,
Math