任何帮助都将非常感激,我目前通过提示输入用户输入的问题,保存为变量,以便它可以通过for循环然后插入到表中。我确定我的错误在于我将插入格式化为表格。
var investment = parseInt(prompt("What will be your initial investment?", "0"), 10);
var interest_rate = parseInt(prompt("What will be your interest rate?", "0"), 10);
var deposit_amount = parseInt(prompt("What will be your monthly deposit?", "0"), 10);
var start_age = parseInt(prompt("What is your age?", "0"), 10);
var beg_balance = 0;
var end_balance = 0;
var daily_interest_rate = interest_rate / 365;
var calculated_interest = 0;
var accrued_interest = 0;
var cumulative_deposits = 0;
var day = 0;
document.write("<table>")
document.write("<tr><th>Age</th><th>Beg Balance</th><th>Interest</th><th>Deposits</th><th>Ending Balance</th></tr>")
beg_balance = investment;
for (var yearly = start_age + 1; yearly <= end_age; yearly++)
{
for (var daily = 1; daily <= 365; daily++)
{
day++;
calculated_interest = (daily_interest_rate) * (beg_balance + cumulative_deposits + accrued_interest);
accrued_interest += calculated_interest;
if (day == 30)
{
day = 0;
cumulative_deposits += deposit_amount;
}
}
end_balance = beg_balance + cumulative_deposits + accrued_interest;
document.write("<tr>");
document.write("<td>" + yearly.toFixed(2) + "</td><td>" + beg_balance.toFixed(2) + "</td><td>" + accrued_interest.toFixed(2) + "</td><td>" + cumulative_deposits.toFixed(2) + "</td><td>" + end_balance.toFixed(2) + "</td>");
document.write("</tr>");
beg_balance = end_balance;
cumulative_deposits = 0;
accrued_interest = 0;
}
document.write("</table>")
答案 0 :(得分:0)
没有定义“end_age”。没有什么可以循环的。