Table 中未显示 ParseInt 提示
ParseInt Prompt not displaying in Table
任何帮助将不胜感激,我目前在提示用户输入时遇到问题,将其保存为变量以便它可以通过 for 循环然后插入 table。我确定我的错误在于我将插入格式设置为 table.
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>")
没有"end_age"定义。没有什么可以循环的。
任何帮助将不胜感激,我目前在提示用户输入时遇到问题,将其保存为变量以便它可以通过 for 循环然后插入 table。我确定我的错误在于我将插入格式设置为 table.
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>")
没有"end_age"定义。没有什么可以循环的。