为了账号安全,请及时绑定邮箱和手机立即绑定

抵押摊销支付计算

抵押摊销支付计算

Helenr 2021-10-14 15:55:31
我正在尝试解决一个作业问题,该问题要求我计算抵押贷款的付款,但是当我输入抵押金额时,例如: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 个输出:按年按揭 贷款利率按揭金额总利息金额总按揭金额我没有收到任何错误消息,但它没有更新任何每月付款,而且看起来一团糟
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

我在这 3 条评论和我的朋友的帮助下编辑了我的代码,他在 javascript 方面更擅长我。我所做的主要事情是将 .toFixed(2) 函数添加到 2 个小数点以解决 JS 中的小数问题。我完全重新组织了变量,我像评论所说的那样将每月付款放在 for 循环中,主要问题是我没有为循环创建一个 var 以用于抵押贷款余额,我还将利息乘以100 等于一个百分比,差不多就是这样,它输出的正是我想要的。


var LoanAmount = parseFloat(prompt("Enter the loan amount:",));

var NumOfYears = parseInt(prompt("Enter the term years:",));

var MortgageLoanBalance;

var TotalLoan;

var TotalInterestAmount;

var MonthlyPayment;

var I;


I = 0.0575;

MonthlyPayment = (((I / 12) * LoanAmount)  / (1- (Math.pow (1+ (I / 12), 

(NumOfYears * -12)))));

TotalInterestAmount = MonthlyPayment * (NumOfYears * 12) - LoanAmount;

TotalLoan = LoanAmount + TotalInterestAmount;

MortgageLoanBalance = TotalLoan - MonthlyPayment;


document.write("Your mortgage term in years: " + NumOfYears + "<br>");

document.write("Your mortgage interest rate is: " + I * 100 + "% <br>");

document.write("Your mortgage loan amount: $" + LoanAmount.toFixed(2) + "<br>" );

document.write("Your total interest amount: $" + TotalInterestAmount.toFixed(2) + 

"<br>");

document.write("Your total mortgage amount: $" + TotalLoan.toFixed(2) + "<br>"); 

document.write("<br>");

document.write("Your Monthly payments begins now for your " + NumOfYears + " years

" + "<br>");

document.write("<br>");


var m = MortgageLoanBalance;

for (m = MortgageLoanBalance; m >= 0; m--) {

document.write("Your Monthly Payment is: $" + MonthlyPayment.toFixed(2) + "<br>");

document.write("Your Mortgage loan balance this month is: $" + m.toFixed(2) +   

"<br>");

document.write("<br>")

    m -= MonthlyPayment;


if (m <= 0) {

    document.write("This is the Ending Amortization Calculator.....");

    }

}


查看完整回答
反对 回复 2021-10-14
  • 1 回答
  • 0 关注
  • 216 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信