Forum Discussion
JadeKelsall
5 years agoCommunity Member
Help with javascript calcuation
This is a highly niche request but I am hoping that someone who knows more about javascript that I do can help me with a calculator I'm trying to create for calculating 95% confidence intervals.
H...
XavierToyos
5 years agoCommunity Member
Hi Jade,
I think I have discovered what happens to your Javascript. Here is the correct Javascript...
var player = GetPlayer();var a = player.GetVar("pct");var b = player.GetVar("n");a = Number.parseFloat(a);b = Number.parseFloat(b);x = a-(1.96*(Math.sqrt((a*(100-a)/b))));;y = a+(1.96*(Math.sqrt((a*(100-a)/b))));;player.SetVar("CILower",x);player.SetVar("CIUpper",y);
You do nothing wrong, the variable becomes a string and you have to convert the string into a variable with the Number.parseFloat() function. If you don't want decimals, use the ParseInt() function.
Hope this can help you
- JadeKelsall5 years agoCommunity Member
Brilliant, that has fixed the issue! Thank you so much for your help :-)