The sum of the lengths of any two sides of a triangle must be greater than the length of the third side. For example, the numbers 3, 4, and 5 can form a triangle because 3+4 > 5, 4+5 > 3, and 5+3 > 4. In contrast, the numbers 1, 2, and 5 cannot form a triangle because 1+2 < 5. Thus, if you are given any three integers, you can determine whether they could possibly form a triangle or not by applying this general principle.
Write a JavaScript program that allows a user to input three integers using text boxes in a form. (Hint: You need to use the built-in parseInt function to convert the input strings to integers.) Test the three integers to determine if they can be formed into a triangle using the rule given above. Also test if the resulting triangle would be a right triangle using the Pythagorean theorem, namely that the square of the hypotenuse (the longest side) equals the sum of squares of the other two sides. Display an alert box to inform the user whether their integers can form a triangle or a right
1
Expert's answer
2013-02-14T08:24:03-0500
<!DOCTYPE html> <head> <title> Tric calc </title> <script type="text/javascript"> function calculate(){ first=parseInt(document.myForm.firstSide.value); second=parseInt(document.myForm.secondSide.value); third=parseInt(document.myForm.thirdSide.value); if (first>=second+third || second>=first+third || third>=first+second){ alert('It is impossible to create a tric'); } else{ alert('It is possible to create a tric'); if (sqr(first)==sqr(second)+sqr(third) || sqr(second)==sqr(first)+sqr(third) || sqr(third)==sqr(first)+sqr(second)){ alert('tric is right'); }
}
return(0); } function sqr(a){ return a*a; } </script>
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment