updated it with the addition of arrays, but it still doesn't work! Also, my teacher wants the slope displayed as a fraction, but I could only think of doing it by concatenating with + "/" +, which makes it difficult when both numbers are - or the denom. is 0. Is there any chance of displaying it as a fraction and at the same time deal with the 0 as the denom. and having both numbers negative? Thanks a lot!!!!!!!!!!!!!!!!!!!! 🙁
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Project: Triangle Calculations Javascript</title>
<SCRIPT TYPE= "text/javascript">
<!--
function process()
{
var x = new Array();
x[0] = myForm.x1.value;
x[1] = myForm.x2.value;
x[2] = myForm.x3.value;
var y = new Array();
y[0] = myForm.y1.value;
y[1] = myForm.y2.value;
y[2] = myForm.y3.value;
var tType = new Array();
tType[0] = "This is an equilateral triangle.";
tType[1] = "This is an isoceles triangle!";
tType[2] = "This is a scalene triangle!";
var tExplain = new Array();
tExplain[0] = "blah";
tExplain[1] = "blah";
tExplain[2] = "and more blah";
var slo1 = Math.round(y[1] - y[0]) + "/" + Math.round(x[1] - x[0]);
var slo2 = Math.round(y[0] - y[2]) + "/" + Math.round(x[0] - x[2]);
var slo3 = Math.round(y[1] - y[2]) + "/" + Math.round(x[1] - x[2]);
var dis1 = Math.round(Math.sqrt((x[1] - x[0])*(x[1] - x[0]) + (y[1] - y[0])*(y[1] - y[0])));
var dis2 = Math.round(Math.sqrt((x[2] - x[0])*(x[2] - x[0]) + (y[2] - y[0])*(y[2] - y[0])));
var dis3 = Math.round(Math.sqrt((x[2] - x[1])*(x[2] - x[1]) + (y[2] - y[1])*(y[2] - y[1])));
if ( dis1 == dis2 && dis1 == dis3 )
{
myForm.tType.value = tType[0];
else if ( dis1 == dis2 || dis1 == dis3 )
myForm.tType.value = tType[1];
else
myForm.tType.value = tType[2];
}
if ( myForm.tType.value = tType[0] )
{
myForm.tExplain.value = tExplain[0];
else if ( myForm.tType.value = tType[1] )
myForm.tExplain.value = tExplain [1];
else
myForm.tExplain.value = tExplain[2];
}
myForm.slope1.value = slo1;
myForm.slope2.value = slo2;
myForm.slope3.value = slo3;
myForm.distance1.value = dis1;
myForm.distance2.value = dis2;
myForm.distance3.value = dis3;
}
//-->
</SCRIPT>
</head>
<body>
<FORM NAME="myForm" ACTION="" METHOD="GET">
<CENTER><FONT COLOR="black"><H3>Testing Triangles</H3></FONT></CENTER>
<HR WIDTH=35% COLOR="blue">
<BR><BR>
<LABEL><B>Please enter the first coordinate (</B></LABEL>
<INPUT TYPE="TEXT" NAME="x1" SIZE=5><LABEL><B>,</B></LABEL><INPUT TYPE="TEXT" NAME="y1" SIZE=5><LABEL><B>)</B></LABEL>
<BR>
<LABEL><B>Please enter the second coordinate ( </B> </LABEL>
<INPUT TYPE="TEXT" NAME="x2" SIZE=5><LABEL><B>,</B></LABEL><INPUT TYPE="TEXT" NAME="y2" SIZE=5><LABEL><B>)</B></LABEL>
<BR>
<LABEL><B>Please enter the third coordinate (</B></LABEL>
<INPUT TYPE="TEXT" NAME="x3" SIZE=5><LABEL><B>,</B></LABEL><INPUT TYPE="TEXT" NAME="y3" SIZE=5><LABEL><B>)</B></LABEL>
<BR><BR>
<TABLE WIDTH="55%" BGCOLOR="gray" BORDER=2 BORDERCOLOR=black align="CENTER">
<TR>
<TD WIDTH="35%" align="center"><B>Slope</B></TD><TD WIDTH="5%" bgcolor="red"> </TD><TD WIDTH="25%" align="center"><B>Distance</B>
</TD>
</TR>
<TR>
<TD WIDTH="35%" align="CENTER">(X<SUB>1</SUB>,Y<SUB>1</SUB>), (X<SUB>2</SUB>,Y<SUB>2</SUB>) = <input type="text" name="slope1" size=10>
</TD>
<TD WIDTH="5%" bgcolor="red"> </TD>
<TD WIDTH="25%" align="CENTER"><input type="text" name="distance1" size=10></TD>
</TR>
<TR>
<TD WIDTH="35%" align="CENTER">(X<SUB>1</SUB>,Y<SUB>1</SUB>), (X<SUB>3</SUB>,Y<SUB>3</SUB>) = <input type="text" name="slope2" size=10>
</TD>
<TD WIDTH="5%" bgcolor="red"> </TD>
<TD WIDTH="25%" align="CENTER"><input type="text" name="distance2" size=10></TD>
</TR>
<TR>
<TD WIDTH="35%" align="CENTER">(X<SUB>2</SUB>,Y<SUB>2</SUB>), (X<SUB>3</SUB>,Y<SUB>3</SUB>) = <input type="text" name="slope3" size=10>
</TD>
<TD WIDTH="5%" bgcolor="red"> </TD>
<TD WIDTH="25%" align="CENTER"><input type="text" name="distance3" size=10></TD>
</TR>
</TABLE>
</CENTER>
<BR><BR>
<LABEL><B>Triangle type:</B></LABEL><BR>
<INPUT TYPE="TEXT" NAME="triType" SIZE=50>
<BR><BR>
<LABEL><B>Explanation of triangle:</B></LABEL><BR>
<TEXTAREA NAME="triExplain" WRAP=VIRTUAL ROWS=9 COLS=50></TEXTAREA>
<BUTTON name="Process" onclick="process()";>Test Triangle</BUTTON>
<BUTTON TYPE=RESET value="Clear All">Clear All </BUTTON>
</FORM>
</BODY>
</HTML>