我是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());
答案 0 :(得分:-2)
您可以使用-ArtifactStagingDirectory
循环或只使用do while
循环。但是,在此过程中,您的余额不会发生变化,因此循环将永远不会退出。