Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6965251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:02:09+00:00 2026-05-27T16:02:09+00:00

I’m reading Javascript – The Definitive Guide . I usually try to imitate the

  • 0

I’m reading Javascript – The Definitive Guide. 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.

I’ve already tried looking for an answer elsewhere, but found nothing.

<html>
<body>
<head><title>Factorials</title></head>



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

<script>
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) &&
        (monthly != Number.POSITIVE_INFINITY) &&
        (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;
}
</script>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:02:10+00:00Added an answer on May 27, 2026 at 4:02 pm

    First thing I notice is that you are missing a bracket:

    if (!isNaN(monthly) &&
    (monthly != Number.POSITIVE_INFINITY) &&
    (monthly != Number.NEGATIVE_INFINITY) *)* {

    I’ve found that JSLint helps me alot with these sort of syntax errors. If you are using an IDE there are some integration tools you can use to get JSLint to work with them.

    Jared also makes an excellent point indirectly about another website, JSFiddle, which can be used to debug HTML+CSS+JS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.