One of the examples in the book "Javascript - The Definitive Guide" not working
<p>I'm reading <em>Javascript - The Definitive Guide</em>. I usually try to imitate the examples they give so I can learn it more quickly, that's just how I learn. But I rewrote this Javascript and it doesn't seem to be working. Whenever I input the numbers and hit calculate it doesn't calculate.</p>

<p>I've already tried looking for an answer elsewhere, but found nothing.</p>

<pre><code>&lt;html&gt;
&lt;body&gt;
&lt;head&gt;&lt;title&gt;Factorials&lt;/title&gt;&lt;/head&gt;



&lt;form name="loandata"&gt;
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td colspan="3"&gt;&lt;b&gt;Enter Loan Information:&lt;/b&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;1)&lt;/td&gt;
            &lt;td&gt;Amount of the loan (any currency):&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="principal" size="12"
                        onchange="calculate();" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;2)&lt;/td&gt;
            &lt;td&gt;Annual percentage rate of interest:&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="interest" size="12"
                        onchange="calculate();" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;3)&lt;/td&gt;
            &lt;td&gt;Repayment period in years:&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="years" size="12"
                        onchange="calculate();" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td colspan="3"&gt;
                &lt;input type="button" value="Compute" onclick="calculate();" /&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td colspan="3"&gt;
                &lt;b&gt;Payment Information:&lt;/b&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;4)&lt;/td&gt;
            &lt;td&gt;Your monthly payment will be:&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="payment" size="12" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;5)&lt;/td&gt;
            &lt;td&gt;Your total payment will be:&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="total" size="12" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;6)&lt;/td&gt;
            &lt;td&gt;Your total interest payments will be:&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="totalinterest" size="12" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;

&lt;script&gt;
function calculate() {
    // Get the user's input from the form. Assume it is all valid.
    // Convert interest from a percentage to a decimal, and convert form
    // an annual rate to a monthly rate. Convert payment period in years
    // to the number of monthly payments.
    var principal = document.loandata.principal.value;
    var interest = document.loandata.interest.value / 100 / 12;
    var payments = document.loandata.years.value * 12;

    // Now compute the monthly payment figure, using esoteric math..
    var x = Math.pow(1 + interest, payments);
    var monthly = (principal*x*interest)/(x-1);

    // Check that the result is a finite number. If so, display the results.
    if (!isNaN(monthly) &amp;&amp;
        (monthly != Number.POSITIVE_INFINITY) &amp;&amp;
        (monthly != Number.NEGATIVE_INFINITY) {

        document.loandata.payment.value = round(monthly);
        document.loandata.total.value = round(monthly * payments);
        document.loandata.totalinterest.value = round((monthly * payments) - principal);
    }
    // Otherwise, the user's input was probably invalid, so don't display anything.
    else {
        document.loandata.payment.value = "";
        document.loandata.total.value = "";
        document.loandata.totalinterest.value = "";
    }
}

// This simple method rounds a number to two decimal places.
function round(x) {
    return Math.round(x*100)/100;
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
