I'm trying to add input boxes so that when this is used people can put in values and then alerts when the script is run based on the results. The script was provided by another user who is difficult to reach to help modify this script. I would like the variables A2 and B2 to be the values input by a user. My feeble attempt at making this do what I want is below the other users example.
My non-working example from
Code:
// JavaScript Example
var answer; // float, make sure to round to 4 decimal places
if(A2<B2) // most likely losing the attack/agility roll
{
if(A2<B2/3)
{answer = 0.0000; }
else
{answer = ((1/2*((1.5*A2)-(0.5*B2)+1)^2)/((A2+1)*(B2+1))); }
}
else
{ // most likely winning the attack/agility roll
if(A2>B2*3)
{answer = 1.0000;}
else // includes ties
{answer = 1-((1/2*((1.5*B2)-(0.5*A2)+1)^2)/((A2+1)*(B2+1))); }
}
My non-working example from
Code:
<script type="text/javascript">
function strTheRoll()
// if(strYOU<strOP) // most likely losing the attack/agility roll
{
{
var answer=""; // float, make sure to round to 4 decimal places
if(strYOU<strOP/3)
{
answer = 0.0000;
alert("the answer is "+answer);
}
else
{
answer = ((1/2*((1.5*strYOU)-(0.5*strOP)+1)^2)/((strYOU+1)*(strOP+1)));}
alert("the answer is "+answer);
}
else
{ // most likely winning the attack/agility roll
if(strYOU>strOP*3)
{
answer = 1.0000;}
alert("the answer is "+answer);
}
else // includes ties
{
answer = 1-((1/2*((1.5*strOP)-(0.5*strYOU)+1)^2)/((strYOU+1)*(strOP+1)));
alert("the answer is "+answer);
}
}
</script>