我正在尝试解决一个作业问题,该问题要求我计算抵押贷款的付款,但是当我输入抵押金额时,例如:500000 和 30 年的期限,它直到 0 才会更新每月付款。将显示摊销计划的 javaScript 应用程序。应用程序将提示用户输入贷款金额(无逗号)。应用程序将提示用户输入术语年(30 或 15)。将计算并显示每月支付 5.75% 的利息。
提示:
您可以修改上周的抵押贷款申请。
将利率设置为 0.0575
计算每月付款的公式是 (((I / 12) * P) / (1-(Math.pow (1+ (I / 12), (Y * -12))))).toFixed(2);
I = 利率
P = 贷款本金(贷款金额)
Y = 任期年
总利息金额的公式是 monthly payment x term Months - loan amount
总贷款的公式是 loan amount + total interest
按揭贷款余额的公式是 total loan - monthly payment
使用 for 循环显示付款和余额
使用 if 语句打印“Ending....”
使用.toFixed(2)转换一个号码只保留两位小数
var I = 0.0575;
var LoanAmount = parseFloat(prompt("Enter the loan amount:",0));
var NumOfYears = parseInt(prompt("Enter the term years:",0));
var MortgageLoanBalance;
//var TermMonth = ;
var MonthlyPayment;
MonthlyPayment = (((I / 12) * LoanAmount) / (1- (Math.pow (1 + (I / 12), (NumOfYears * -12))))).toFixed(2);
var TotalInterestAmount = MonthlyPayment * (NumOfYears * 12) - LoanAmount;
var TotalLoan = LoanAmount + TotalInterestAmount;
MortgageLoanBalance = TotalLoan - MonthlyPayment;
//alert(MortgageLoanBalance);
if (MortgageLoanBalance > 0 ) {
document.write("Your " + NumOfYears + " year mortgage amount is " + MonthlyPayment + " per month." );
//else if (MortgageLoanBalance > 0)
document.write(TotalInterestAmount);
document.write(TotalLoan);
document.write(MortgageLoanBalance);
for (i = 0; i <= MonthlyPayment; i++) {
document.write("Month " + i + ": Your Monthly Payment " + MonthlyPayment + " and Mortgage loan balance " + MortgageLoanBalance + "<br>");
}
} else {
document.write("You have no payments");
//document.write("I don't know what you did.")
}
它应该打印出 5 个输出:
按年
按揭 贷款利率
按揭金额
总利息金额
总按揭金额
我没有收到任何错误消息,但它没有更新任何每月付款,而且看起来一团糟
慕桂英3389331
相关分类