Question:

I am taking a college class "Programming in Java script" and desperately need help with my assignment.

by  |  earlier

0 LIKES UnLike

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 triangle (tell them which), or if the integers cannot form a triangle. Continue accepting sets of three integers and testing them until the user decides to quit.

 Tags:

   Report

2 ANSWERS


  1. Your forgot to ask a question.


  2. <form onsubmit="triangle();return false;"><input type="text" name="n1" /><input type="text" name="n2" /><input type="text" name="n3" />

    <input type="submit"></form>

    <script language="JavaScript" type="text/javascript">

    function triangle ()

    {

      var big = parseInt (document.forms[0].n1.value), small1 = parseInt (document.forms[0].n2.value), small2 = parseInt (document.forms[0].n3.value), temp = 0;

      if (big <= 0 || small1 <= 0 || small2 <= 0) { alert ("Invalid length size"); return false; }

      temp = small1; small1 = Math.max (small1, small2); if (small1 == small2) { small2 = temp; }

      temp = big; big = Math.max (big, small1); if (big == small1) { small1 = temp; }

      if (small1 + small2 <= big) { alert ("No triangle"); }

      else

      {

        if (small1*small1 + small2*small2 == big*big) { alert ("Right triangle"); }

        else { alert ("Triangle"); }

      }

    }

    </script>

    Please check it against your own logics :)

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions