papiculo
Mar 10th 2008, 4:43 pm
Let me start by saying this is for my second project in my Javascript class. I am not asking anyone do it for me. Frankly I'd rather figure it out myself. Although I am in the need of a little direction. There are several parts of this project but this part seems to getting the best of me.
What I am trying to do is determine whether a triangle is isosceles, scalene, or equilateral. And then print out the result. I have both scalene and equilateral working correctly. And I believe isosceles as well. The problem occurs when printing out the result. Since an isosceles has two sides that are equal when I enter in 3 of the same number, my program prints out the statement for both isosceles and equilateral.
Here are the two functions i have for checking the triangle.
function isIsosceles(s1,s2,s3)
{
if (s1 == s2 || s2 == s3 || s1 == s3)
{
return true;
}
}
function isEquilateral(s1,s2,s3)
{
if (s1 == s2 && s2 == s3)
{
return true;
}
}
Here is my code for printing the results:
if (isIsosceles(s1,s2,s3) == true)
{
document.write("<br>The triangle is isosceles");
}
if (isEquilateral(s1,s2,s3) == true)
{
document.write("<br>The triangle is equilateral");
}
When the user inputs 5, 5, 5. Both statements print.
Can anyone provide a little guidance?
What I am trying to do is determine whether a triangle is isosceles, scalene, or equilateral. And then print out the result. I have both scalene and equilateral working correctly. And I believe isosceles as well. The problem occurs when printing out the result. Since an isosceles has two sides that are equal when I enter in 3 of the same number, my program prints out the statement for both isosceles and equilateral.
Here are the two functions i have for checking the triangle.
function isIsosceles(s1,s2,s3)
{
if (s1 == s2 || s2 == s3 || s1 == s3)
{
return true;
}
}
function isEquilateral(s1,s2,s3)
{
if (s1 == s2 && s2 == s3)
{
return true;
}
}
Here is my code for printing the results:
if (isIsosceles(s1,s2,s3) == true)
{
document.write("<br>The triangle is isosceles");
}
if (isEquilateral(s1,s2,s3) == true)
{
document.write("<br>The triangle is equilateral");
}
When the user inputs 5, 5, 5. Both statements print.
Can anyone provide a little guidance?