Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Creating a Pythagorean Theorem Calculator (Simple!)

    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:

    [CODE]
    <html>
    <head>
    <title>A Pythagoras Conversion</title>
    </head>

    <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= ");

    </script>

    <body>
    </body>
    </html>
    [CODE]

    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...

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,144
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •