亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

抵押攤銷支付計算

抵押攤銷支付計算

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 關注
  • 245 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號