View Full Version : Creating a Pythagorean Theorem Calculator (Simple!)

12-08-2009, 07:57 PM
Hey guys. This should be extremely easy for you to answer. This is actually for an intro to computers class I am taking and I am completely stumped. Basically I have to create a really simple Pythagorean Theorem calculator and this is what I have so far:

<title>A Pythagoras Conversion</title>

<script type="text/javascript">

var right_leg, left_leg, hypotenuse;

alert ("This calculates the hypotenuse of a right-angled triangle using the Pytahgorean Thereom. Press <OK> to continue!");

right_leg=prompt("Enter the length of the right leg.");

left_leg=prompt("Enter the length of the left leg.");

sq1 = right_leg*right_leg;
sq2 = left_leg*left_leg;

hypotenuse = math.sqrt(sq1 + sq2);

alert ("The Hypotenuse= ");



Everything works except for when it comes to it actually calculating. The calculation window never pops up. Please tell me what I am doing wrong in the calculation here....it is driving me nuts. :/

Thanks so much...

Philip M
12-08-2009, 08:07 PM
hypotenuse = Math.sqrt(sq1 + sq2);
alert ("The Hypotenuse= " + hypotenuse);

"Life is like a mirror, we get the best results when we smile at it. " - Anonymous