如何保持这个循环,直到余额为零?

时间:2018-02-22 03:34:43

标签: javascript

我是Javascript的新手,并且已经想出如何让第一行记录到控制台,但是,如何在余额变低之前继续循环并显示结果,直到余额为零?我很感激任何帮助。提前谢谢。

function displayPayment() {
  var year = 0;
  var balance = 1500;
  var interest = 0.015;
  var minimum = 0.02;
  var payNum = 0;

  if (balance > 0) {
    var newPayNum = payNum + 1;
    var newYear = year + 1;
    var interestPaid = balance * interest;
    var newBalance = interestPaid + balance;
    var minPay = newBalance * minimum;
    var balanceOwe = newBalance - minPay;

    return ("   " + newYear + "   " + balanceOwe + "      " + newPayNum + "            
" + interestPaid);
  }
}
console.log(" Year " + " Balance " + " PaymentNum " + "  InterestPaid \n");
console.log(displayPayment());

1 个答案:

答案 0 :(得分:-2)

您可以使用-ArtifactStagingDirectory循环或只使用do while循环。但是,在此过程中,您的余额不会发生变化,因此循环将永远不会退出。