[英]How do I fix this calculator UI? (Javascript from code.org) I will explain down below
[英]How do I fix the calculator error in my code?
請幫幫我。 我的 javascript 代碼不起作用。 我正在嘗試編寫一個差異化支付計算器。 但是我的代碼不起作用。 看起來錯誤在循環中的某個地方。 我無法理解。 相同的 python 代碼可以正常工作。 我的代碼:
function result_differ() {
amount_of_credit = document.getElementById('amount_of_credit').value;
amount_of_credit = parseFloat(amount_of_credit);
credit_term = document.getElementById('credit_term').value;
credit_term = parseInt(credit_term);
interest_rate = document.getElementById('interest_rate').value;
interest_rate= parseFloat(interest_rate);
initial_fee = document.getElementById('initial_fee').value;
initial_fee = parseFloat(initial_fee);
part_of_the_principal = amount_of_credit / credit_term;
if (initial_fee == 0) {
let loan_payment_amount = [];
let arr_range = range(1, credit_term + 1);
for (let mes = 1; mes <= arr_range.lenght; mes++) {
interest_amount = amount_of_credit * (interest_rate / 100) * 30 / 365;
payment_amount_per_month = part_of_the_principal + interest_amount;
loan_payment_amount.push(payment_amount_per_month);
out.innerHTML = payment_amount_per_month.toFixed(2) + "<br />";
amount_of_credit = amount_of_credit - part_of_the_principal;
}
document.getElementById('success_text_div').style.display = 'block';
} else {
let loan_payment_amount = [];
let arr_range = range(1, credit_term + 1);
loan_amount_minus_installment = amount_of_credit - initial_fee;
part_principal_minus_installment = loan_amount_minus_installment / credit_term;
for (let mes = 1; mes <= arr_range.lenght; mes++) {
interest_amount = loan_amount_minus_installment * (interest_rate / 100) * 30 / 365;
payment_amount_per_month = part_principal_minus_installment + interest_amount;
loan_payment_amount.push(payment_amount_per_month);
out.innerHTML = payment_amount_per_month.toFixed(2) + "<br />";
loan_amount_minus_installment = loan_amount_minus_installment - part_principal_minus_installment;
}
document.getElementById('success_text_div').style.display = 'block';
}
} ```
您在 for 循環中有拼寫錯誤。
for (let mes = 1; mes <= arr_range.lenght; mes++)
它一定要是:
for (let mes = 1; mes <= arr_range.length; mes++)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.