Hello, I'm new to Javascript and I'm trying to write a code that when a user enters three numbers will tell if the numbers can form a triangle or not, or if the triangle is a right triangle. I can't see why the code won't work but I bet someone in here can pinpoint the problem for me. Thank you!
Here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Triangle or Not</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
function checkForTriangle()
{
num1 = parseInt(document.triangleForm.number1.value);
num2 = parseInt(document.triangleForm.number2.value);
num3 = parseInt(document.triangleForm.number3.value);
sideA = (num1 + num2);
sideB = (num1 + num3);
sideC = (num2 + num3);
sideASquared = sideA * sideA;
sideBSquared = sideB * sideB;
sideCSquared = sideC * sideC;
if (sideA > num3 && sideB > num2 && sideC > num1) {
alert("These 3 sides CAN be a triangle");
} else {
alert("These 3 sides CAN NOT be a triangle");
}
if sideASquared == (sideBSquared + sideCSquared) ||
sideBSquared == (sideASquared + sideCSquared) ||
sideCSquared == (sideASquared + sideBSquared) || {
alert("This is a Right Triangle");
}
}
</script>
</head>
<body>
<form name="triangleForm" action="">
<p>Enter number 1:
<input type="text" name="number1"><br>
<p>Enter number 2:
<input type="text" name="number2"><br>
<P>Enter number 3:
<input type="text" name="number3"><br>
<input type="button" value="Is this a Triangle?" onClick="checkForTriangle();">
</p>
</form>
</body>
</html>