[Javascript] Help with Calculator

Andi @ M:tG Ontario andi at mtgontario.com
Sun Dec 9 22:06:04 CST 2001


Hello,
I'm new to this group & very new to JavaScript.

I was hoping someone might be able to help me. I'm having one hell of time trying to get this to work. What I've done is combine 3 different scripts into 1. It's a ratings calculator. I have it mostly working except that it is not showing me my point gain/loss in IE (just NaN and showing the wrong value in Nets!) & it's also not showing the new ratings at all in Netscape (just NaN). You can see it here http://www.mtgontario.com/calculator1.php or view the code below.

I'm not sure how to get this to work. I'm not getting error messages so I have no idea even where the problem is. Usually I just do the javascript: thing in Nets or look at the error messages in IE to try & find the problem & tinker with it until I get it right! I'd appreciate any help I could get with this.

Thanks,
Andi

Ps, if you want to know some correct numbers for this the results would be:

You: 1655
Them: 1866
Loss
Win %: 23
Point g/l: -4
Your New: 1651
Their New: 1870

<script language="JavaScript" type="text/javascript">
<!--
var rating0;
var opponent0;
var my_result;
var my_win_exp;
var my_new_rating;
var my_diff;
var k1=20;

function calc(form)
 {

for (Count = 0; Count < 3; Count++)
  {
    if (form.wld[Count].checked)
    break;
  }

if (Count==0) {my_result=1;} else
if (Count==1) {result=0;} else
{my_result=0.5;}

my_win_exp  = 1 / (Math.pow(10,((form.opponent0.value - form.rating0.value) / 400)) +1);
my_diff  = (k1 * (my_result - my_win_exp));

form.fwinexp.value=Math.round(100*my_win_exp);
form.fmydiff.value=(Math.round(my_diff * 100)) / 100;

if (form.wld[0].checked) scoringpoints = 1;
if (form.wld[1].checked) scoringpoints = 0;
if (form.wld[2].checked) scoringpoints = 0.5;
winprobability = 1 / (Math.pow(10,((parseInt(form.opponent0.value) - parseInt(form.rating0.value)) / 400)) + 1)
form.rating1.value=Math.round(parseInt(form.rating0.value) + (parseInt(form.Kvalue.value) * (scoringpoints - winprobability)))
form.rating2.value=Math.round(parseInt(form.opponent0.value) + (parseInt(form.Kvalue.value) * (winprobability - scoringpoints)))

}

function set_rating0(rating)
{
  rating0 = rating.value;
}

function set_opponent0(rating)
{
  opponent0 = rating.value;
}

function set_kvalue()
{
    var i = document.calcform.Kvalue.selectedIndex;
    k1  = document.calcform.Kvalue.options[i].value;
}

// -->
</script>

<form method="POST" name="calcform">
<div align="center"><center>
<table border="1" bgcolor="#000000" bordercolor="#000000" bordercolordark="#000000" bordercolorlight="#000000">
<tr>
<td colspan="2" bgcolor="#CCCCCC">
<font color="#000000" size="2" face="Verdana"><strong>- Unofficial DCI Ratings Calculator -</strong></font> 
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Your Rating: </strong></font><br>
</td>
<td align="center" bgcolor="#666977"><INPUT TYPE="text" NAME="rating0" SIZE="6" style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana" ONCHANGE="set_rating0(this)"><br>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Opponent's Rating: </strong></font><br>
</td>
<td align="center" bgcolor="#666977">
<INPUT TYPE="text" NAME="opponent0" SIZE="6" style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana" ONCHANGE="set_opponent0(this)"><br>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Match Result: </strong></font><br>
</td>
<td bgcolor="#666977">
<INPUT TYPE="radio" NAME="wld" VALUE="win" CHECKED> <font color="#FFFFFF" size="2" face="Verdana">Win</font><br>
<INPUT NAME="wld" TYPE="radio" VALUE="lose"> <font color="#FFFFFF" size="2" face="Verdana">Loss</font><br>
<INPUT NAME="wld" TYPE="radio" VALUE="draw"> <font color="#FFFFFF" size="2" face="Verdana">Draw</font><br>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;K-value: </strong></font><br>
</td>
<td bgcolor="#666977">
<select name="Kvalue" size="1" style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana" onchange="set_kvalue();">
<option value="8"> 8 </option>
<option selected value="16"> 16 </option>
<option value="20"> 20 </option>
<option value="24"> 24 </option>
<option value="28"> 28 </option>
<option value="32"> 32 </option>
<option value="40"> 40 </option>
<option value="48"> 48 </option>
</select>
</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">
<p align="center"><input type="button" style="BACKGROUND: #000000; BORDER-BOTTOM: #B1B3BC 2px solid; BORDER-LEFT: #B1B3BC 2px solid; BORDER-RIGHT: #B1B3BC 2px solid; BORDER-TOP: #B1B3BC 2px solid; COLOR: #B1B3BC"  style="font-family:verdana" value="Calculate" 
onclick="calc(this.form)"> </p>
</td>
<td align="center" bgcolor="#FFFFFF">
<p align="center"><input type="reset" style="BACKGROUND: #000000; BORDER-BOTTOM: #B1B3BC 2px solid; BORDER-LEFT: #B1B3BC 2px solid; BORDER-RIGHT: #B1B3BC 2px solid; BORDER-TOP: #B1B3BC 2px solid; COLOR: #B1B3BC"  style="font-family:verdana" value="Reset"> </p>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Win Expectancy %: </strong></font><br>
</td>
<td align="center" bgcolor="#666977"><input type="text" size="6"  style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana" name="fwinexp"><br>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Point Gain/Loss: </strong></font><br>
</td>
<td align="center" bgcolor="#666977">
<input type="text" size="6"  style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana" name="fmydiff"><br>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Your New Rating: </strong></font><br>
</td>
<td align="center" bgcolor="#666977">
<INPUT TYPE="text" NAME="rating1" size="6"  style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana"><br>
</td>
</tr>
<tr>
<td bgcolor="#B1B3BC">
<font color="#000000" size="2" face="Verdana"><strong>&nbsp;Their New Rating: </strong></font><br>
</td>
<td align="center" bgcolor="#666977">
<INPUT TYPE="text" NAME="rating2" size="6"  style="background:#B1B3BC" style="border-color:#C0C0C0" style="color:#000000" style="font-family:verdana"><br>
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#C0C0C0">
<center>
<font color="#000000" size="2" face="Verdana"><b>Author: <a href="mailto:andi at mtgontario.com">Andi @ M:tG Ontario.com</a></b></font>
</center>
</td>
</tr>
</table>
</center></div>
</form>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20011209/dc1bf319/attachment.htm>


More information about the Javascript mailing list