Recently I asked a question regarding my triangle calculations Coded in JavaScript. Basically I went to JSLint (A JavaScript debug facility) to acquire some data as to why nothing inside the function and procedure is working where as it all looks good and I followed previously given advice, but I believe this is a separate issue. I have posted the code below:
<html>
<head>
<link href="stylesheet/stylesheet.css" rel="stylesheet" type="text/css">
<script language="Javascript" type="text/javascript">
/* Key/Legend
Var
inp1 = input1
inp2 = input2
inp3 = input3
Triangle_Inputs = Form Name
*/
/* Notes
In computing, a parser is one of the components in an interpreter or
compiler that checks for correct syntax and builds a data structure
(often some kind of parse tree, abstract syntax tree or other hierarchical structure)
implicit in the input tokens.
Technique
if (side1 is equal to side2 AND side 2 is equal to side3) {equalitateral}
if (side1 is equal to side2 AND side 2 doesn't equal to side3) {isosceles}
if (side1 doesn't equal to side2 AND side2 doesn't equal to side 3 AND side 3 doesn't equal side 1) {scalene}
http://www.w3schools.com/js/js_comparisons.asp
*/
function checkinputs(){
/* Var = parseInt(document.Name_Of_Element_Form.Field_Name(Input).value); */
/* Input Fields */
inp1 = parseInt(document.Triangle_Inputs.input1.value);
inp2 = parseInt(document.Triangle_Inputs.input2.value);
inp3 = parseInt(document.Triangle_Inputs.input3.value);
/* Side options */
sideA = (inp1);
sideB = (inp2);
sideC = (inp3);
if (sideA == sideB && sideB == sideC) {
alert("Equalateral");
}
if (sideA == sideB && != sideC) {
alert("Isosceles");
}
if (sideA != sideB == sideC) {
alert("Isosceles");
}
if (sideA != sideB != sideC != sideA) {
alert("Scalene!");
}
}
</script>
</head>
<body>
<div id="Container">
<div id="Header"><h1></h1></div>
<div id="Content_1">
<div id="Explanation">
This calculator will determine what
triangle you have made depending on
the integer values in the input fields.
</div>
<div id="Form">
<FORM NAME="Triangle_Inputs" METHOD="GET">
Enter the triangle values below: <br>
<p>
<h4>Side 1: </h4><BR>
<INPUT TYPE="Integer" NAME="input1" VALUE=""><P>
<h4>Side 2: </h4><BR>
<INPUT TYPE="Integer" NAME="input2" VALUE=""><P>
<h4>Side 3:</h4> <BR>
<INPUT TYPE="Integer" NAME="input3" VALUE=""><P>
<INPUT TYPE="button" NAME="Submit" Value="Submit" Class="Submit" onClick="checkinputs()">
</FORM>
</div>
<div id="Verbal_Output">
<h2>You made a:</h2>
<p>
<h2>Triangle</h2>
</div>
</div>
<p>
<p>
<div id="Content_2">
<div id="Image_Output">asdad</div>
</div>
</div>
</body>
</html>
This is the site itself, Ignoring the div tags. I want to know why I can’t click the button and more the the point why JSlint says:
inp1 = parseInt(document.Triangle_Inputs.input1.value);
line 39 character 1 ‘inp1’ was used before it was defined.
for the inp1,inp2 and inp3.
edit:
My understanding of using Variables was incorrect, I was listing them without using “,”s.
Instead I was calling one variable and the rest I wasn’t.
Try this:
I noticed also that your logic is a little bit flawed, so I’ve edited it to what I think looks right.