加载数组时JavaScript崩溃

时间:2018-11-21 14:28:43

标签: javascript jquery

当此函数加载导致计算结果较长时,加载此函数导致浏览器崩溃时,我遇到了问题。

当回报大于2000时,系统崩溃

function getPayments (minimumPayment, originalBalance, interestRate) {

    var balance = document.getElementById("balance").value;
    const payments = [];
    while(1) {
        let balance = originalBalance / 1;
        let payment = minimumPayment * balance / 100;
        if (payment < 10) payment = 10;
        const interest = ((interestRate / 12) * balance / 100);
        const principal = payment - interest;

        //alert(principal;
        balance -= principal;

        payments.push({
            payment: +payment.toFixed(2),
            principal: +principal.toFixed(2),
            balance: +balance.toFixed(2)
        })
        originalBalance = balance;

        if(interest <= 0) break;
    }
    console.log(payments);

    return payments;
}

1 个答案:

答案 0 :(得分:0)

您遇到了无限循环。您试图在兴趣下降而您的代码似乎没有做到这一点时打破循环