flipwebdomains.com
Results 1 to 2 of 2

Thread: Help with javascript

  1. #1
    Join Date
    Apr 2004
    Posts
    537
    Rep Power
    0

    Default Help with javascript

    A friend of mine ask me to help her with a problem the thing is i have not done javascript in many years now. I cant seem to get the loop to run

    Question
    Write an algorithm that takes two numbers and calculates the
    product of the numbers using the binary operator '+' only i.e. the
    algorithm should NOT use the binary operator 'x'.

    Solution
    <html>
    <head>
    <title>
    Calculator
    </title>
    <SCRIPT LANGUAGE="JavaScript">


    <!-- Begin
    function doMath() {
    var one = eval(document.theForm.elements[0].value)
    var two = eval(document.theForm.elements[1].value)
    count = 0

    while (count<=two)
    {
    var prod = one + one
    count == count +1
    }


    alert("The product of " + one + " and " +
    two + " is " + prod + ".")
    }
    // End -->
    </SCRIPT>

    </head>

    <body>

    <CENTER>
    <FORM NAME="theForm">
    Multiply
    <INPUT TYPE="text">
    By
    <INPUT TYPE="text">
    <INPUT TYPE="button" VALUE="Show result" onClick="doMath()">
    </FORM>
    </CENTER>

    </body>
    </html>
    Wise men talk because they have something to say; fools, because they have to say something. Live for computers or else they will live for you.
    8368993 (lime) 303-1359 (digi) blunt60us@yahoo.com

  2. #2
    Join Date
    Apr 2004
    Posts
    537
    Rep Power
    0

    Default

    Dont worry i found the error solution is below

    <html>
    <head>
    <title>
    Calculator
    </title>
    <script type="text/javaScript">


    <!-- Begin
    function doMath() {
    var one = eval(document.theForm.elements[0].value);
    var two = eval(document.theForm.elements[1].value);
    var prod=0;

    for (var i=0; i<two; i++)
    {
    prod = prod + one;
    }
    alert("The product of " + one + " and " +
    two + " is " + prod + ".")
    }
    // End -->
    </script>

    </head>

    <body>

    <CENTER>
    <FORM NAME="theForm">
    Multiply
    <INPUT TYPE="text">
    By
    <INPUT TYPE="text">
    <INPUT TYPE="button" VALUE="Show result" onClick="doMath()">
    </FORM>
    </CENTER>

    </body>
    </html>
    Wise men talk because they have something to say; fools, because they have to say something. Live for computers or else they will live for you.
    8368993 (lime) 303-1359 (digi) blunt60us@yahoo.com

Posting Permissions

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