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
Indeed not to difficult. The square math is already there. Only thing needed was to set the type of calculation on the square button to 's'.player.SetVar("calculation", "s");
The math for square root wasnot yet present in your code, but luckily Javascript has its own math functionality so using 'Math.sqrt' was easy enough.mysum = Math.sqrt(mysum);
Setting the calculation to 'r' on the square root button...player.SetVar("calculation", "r");
As the actual calculation just happens on the '='-button inthere another change needed. } else if (mycalc == "r") {
mysum = Math.sqrt(mysum);
And thats it. Adding the fixed sample.