は、私がこのプログラムに問題を抱えています。私は年の最初の数を得る方法を考え出すことはできません(最初の年が失われていることに気づく)。私もゼロで終了するために私のwhileループをフォーマットしましたが、私はまだ-20.82を取得し、テーブルの一番下には未定義です。最後に、私はすべてを見てきましたが、計算する正しい数式を見つけることができません。私はほとんどそれを得たように感じますが、私は重要な部分を欠いています。助けてください!表の書式のJavascript
function displayWelcome() {
var welcome = "This program will determine the time to pay off a credit card and interest paid based on the current balance, the interest rate, and the monthly payments made.";
return welcome;
}
function calculateMinimumPayment(bal, intr) {
var min = bal * intr;
return min;
}
function displayPayments(bal, intr, min) {
var top1 = "Balance on your credit card: " + bal + "\nInterest Rate: " + intr + "\nAssuming the minimum payment of 2% of the balance ($20 min)\nYour minimum payment would be $" + min;
var top2 = "PAYOFF SCHEDULE\n\n______________\nYear\tBalance\t\tPayment Num\tInterest Paid\n";
console.log(top1);
console.log(top2);
var yearcount = 0;
var year = 1;
var paynum = 0;
while (bal >= 0) {
paynum++;
yearcount++;
bal = (bal+(intr-min));
intrp = intr+(bal*min);
var tbl1 = parseFloat(bal).toFixed(2) + "\t\t" + paynum + "\t\t" + parseFloat(intrp).toFixed(2);
var tbl2 = " " + year + " " + tbl1;
if (yearcount % 12 === 0) {
year = year+1;
var tbl2 = " " + year + " " + tbl1;
} else {
tbl2 = "\t" + tbl1;
}
console.log(tbl2);
}
}
console.log(displayWelcome());
console.log(displayPayments(1500,0.18,calculateMinimumPayment(1500, 0.02)));
ここでは出力です:
This program will determine the time to pay off a credit card and interest paid
based on the current balance, the interest rate, and the monthly payments made.
Balance on your credit card: 1500
Interest Rate: 0.18
Assuming the minimum payment of 2% of the balance ($20 min)
Your minimum payment would be $30
PAYOFF SCHEDULE
______________
Year Balance Payment Num Interest Paid
1470.18 1 44105.58
1440..98
1410.54 3 42316.38
1380.72 4 41421.78
1350.90 5 40527.18
1321.08 6 39632.58
1291.26 7 38737.98
1261.44 8 37843.38
1231.62 9 36948.78
1201.80 10 36054.18
1171.98 11 35159.58
2 1142.16 12 34264.98
1112.34 13 33370.38
1082.52 14 32475.78
1052.70 15 31581.18
1022.88 16 30686.58
993.06 17 29791.98
963.24 18 28897.38
933.42 19 28002.78
903.60 20 27108.18
873.78 21 26213.58
843.96 22 25318.98
814.14 23 24424.38
3 784.32 24 23529.78
754.50 25 22635.18
724.68 26 21740.58
694.86 27 20845.98
665.04 28 19951.38
635.22 29 19056.78
605.40 30 18162.18
575.58 31 17267.58
545.76 32 16372.98
515.94 33 15478.38
486.12 34 14583.78
456.30 35 13689.18
4 426.48 36 12794.58
396.66 37 11899.98
366.84 38 11005.38
337.02 39 10110.78
307.20 40 9216.18
277.38 41 8321.58
247.56 42 7426.98
217.74 43 6532.38
187.92 44 5637.78
158.10 45 4743.18
128.28 46 3848.58
98.46 47 2953.98
5 68.64 48 2059.38
38.82 49 1164.78
9.00 50 270.18
-20.82 51 -624.42
undefined
は、あなたがより多くの情報が必要なら、私に教えてください。
あなたのコードを下げることができますか?または最小限のコードを表示するだけですか? – evolutionxbox