Equations

Comments

1 comment

  • Abbey Desjarlais

    Hi Jack,

    I've created an example that takes two numbers from the user, multiplies them together, then displays the result.

     

    <!-- Section 1 -->
    <section name="section1">
    <title>Inputs to an Equation</title>

    <!-- Create variables for the numbers you want entered and calculated -->
    <script>
    local length = 0
    local width = 0
    local area = 0
    </script>

    <!-- Create text boxes and labels describing what to input -->
    <p>Enter the length here:</p>
    <textField name="lengthInput" />

    <p>Enter the width here:</p>
    <textField name="widthInput" />

    <!-- On button click, the numbers entered in the text boxes are assigned to variables, then the area is calculated and output to a paragraph -->
    <button content="Calculate Area">
    <onClick>
    length = tonumber(lengthInput.Text)
    width = tonumber(widthInput.Text)
    area = length*width
    outputPar.Text = string.format("Area = %.2f", area)
    </onClick>
    </button>

    <p name="outputPar">
    Area =
    </p>
    </section>

     

    The only tricky thing to remember when using textFields is that the field expects the user to enter text, not numbers, so we need to convert the input text to a number value using the "tonumber" function (e.g. tonumber(lengthInput.Text)).

    0
    Comment actions Permalink

Please sign in to leave a comment.