I have this code and need to have it on a table but the table is not creating. What am I doing wrong?

<!DOCTYPE html> <html> <body> <script>
var investment     = 2000;
var interest_rate  = .12;
var deposit_amount = 100;
var start_age      = 44;
var end_age        = 65;
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 days           = 0;
document.write("<table>")
document.write("<tr><th>Age</th><th>Beg Bal</th><th>Interest</th><th>Deposits</th><th>Ending Bal</th></tr>")
beg_balance = investment;
for (var yearly = start_age + 1; yearly <= end_age; yearly++) 
    {
        for (var daily = 1; daily <= 365; daily++) 
    {
        days++;
        calculated_interest = (daily_interest_rate) * (beg_balance + cumulative_deposits + accrued_interest);
        accrued_interest += calculated_interest;
        if (days == 30) 
        {
        days = 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>")
</script>
// JavaScript Document
</body> </html> 

I tried your code and the table gets generated OK. I get this:

Age Beg Bal Interest    Deposits    Ending Bal
45.00   2000.00 324.65  1200.00 3524.65
46.00   3524.65 521.09  1200.00 5245.75
47.00   5245.75 742.58  1200.00 7188.33
48.00   7188.33 992.31  1200.00 9380.63
49.00   9380.63 1273.87 1200.00 11854.50
50.00   11854.50    1591.33 1300.00 14745.83
51.00   14745.83    1949.42 1200.00 17895.25
52.00   17895.25    2352.98 1200.00 21448.23
53.00   21448.23    2807.99 1200.00 25456.22
54.00   25456.22    3321.00 1200.00 29977.22
55.00   29977.22    3899.41 1200.00 35076.63
56.00   35076.63    4551.56 1300.00 40928.19
57.00   40928.19    5287.01 1200.00 47415.20
58.00   47415.20    6116.02 1200.00 54731.22
59.00   54731.22    7050.72 1200.00 62981.95
60.00   62981.95    8104.58 1200.00 72286.52
61.00   72286.52    9292.77 1200.00 82779.30
62.00   82779.30    10632.44    1300.00 94711.74
63.00   94711.74    12143.04    1200.00 108054.78
64.00   108054.78   13846.03    1200.00 123100.81
65.00   123100.81   15766.11    1200.00 140066.92

What browser and what environment are you using? Is Javascript enabled? Do you get any errors in the console? Have you looked at the generated HTML source?

Also, are you running it on HTM5? If not, you may need to update <script> to <script type="text/javascript"> just in case.

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.