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 8009829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:33:39+00:00 2026-06-04T18:33:39+00:00

I’m trying to make a simple credit card repayment calculator script but seem to

  • 0

I’m trying to make a simple credit card repayment calculator script but seem to be having a problem with a “while” loop. It works for low numbers, but when you start putting in higher numbers it freezes the browser, then you have to quit and reopen.

Here is the JavaScript (jQuery) I have:

$('#calculate').click(function()
{
    var currentBalance = parseFloat($('#current_balance').val().substring(1)); // substring so it doesnt grab the £ sign
    var interestRate = parseFloat($('#interest_rate').val());
    var interestType = $('#interest_type').val();
    var monthlyPayment = parseFloat($('#monthly_payment').val().substring(1));
    var totalInterest = 0;
    var interest = 0;
    var months = 0;

    while(currentBalance > 0) // while there is still a balance on the card run the following
    {
        interest = (currentBalance/100)*interestRate; // find interest amount for this month

        currentBalance = currentBalance+interest; // add the interest to the balance

        currentBalance = currentBalance-monthlyPayment; // subtract monthly payment from balance

        totalInterest = totalInterest+interest; // total amount of interest paid
        months++;
    }

    var years = parseInt(months / 12);
    var remainingMonths = months % 12;

    totalInterest = Math.round(totalInterest);

    $('#clear_balance').val(years+' years and '+remainingMonths+' months');
    $('#interest_paid').val('£'+totalInterest);
});

and here is my HTML:

        <table id="card-info">
            <tbody>
                <tr>
                    <td><label for="current_balance">Current balance</label></td>
                    <td><input type="text" id="current_balance" /></td>
                </tr>
                <tr>
                    <td><label for="interest_rate">Interest rate</label></td>
                    <td>
                        <input type="text" id="interest_rate" />
                        <select id="interest_type">
                            <option value="monthly">Monthly</option>
                            <option value="yearly">Yearly</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><label for="monthly_payment">Monthly payment</label></td>
                    <td><input type="text" id="monthly_payment" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td colspan="2"><button id="calculate">Calculate</button></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="results">
        <table id="results-info">
            <tbody>
                <tr>
                    <td>
                        <label for="clear_balance">Time to clear balance</label><br />
                        <input type="text" id="clear_balance" />
                    </td>
                    <td>
                        <label for="interest_paid">Total interest paid</label><br />
                        <input type="text" id="interest_paid" />
                    </td>
                </tr>
            </tbody>
        </table>

Is there anything I am doing wrong?

  • 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-06-04T18:33:41+00:00Added an answer on June 4, 2026 at 6:33 pm

    Your code doesn’t account for the case where the montly payment is insufficient to cover the interest charged each month.

    In those circumstances it’ll go into an infinite loop, because the loan never gets paid off!

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.