63 173
Assignments Done
Successfully Done
In July 2018

Answer to Question #24220 in AJAX | JavaScript | HTML | PHP for autumn reid

Question #24220
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
Expert's answer
<!DOCTYPE html>
<title> Tric calc </title>
<script type="text/javascript">
function calculate(){
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');


function sqr(a){
return a*a;

<form name="myForm">
Input first side:
<input type="textbox" name="firstSide" value="0">
Input second side:
<input type="textbox" name="secondSide" value="0">
Input third side:
<input type="textbox" name="thirdSide" value="0">
<tr><td colspan="2"><input type="button" name="submitButton" value="Triangle calculation" onclick="calculate()"></td></tr>

<p id='possible'></p>
<p id='rightTriangle'></p>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions