Question
I just ask a question about some javascript and the answers I received are not working unfortunately. From the code attached 600 for investment, 5
I just ask a question about some javascript and the answers I received are not working unfortunately. From the code attached 600 for investment, 5 for growth and 4 for time should give 630, 1291.50, 1986.50, and 2715.08 in order form year 1 to 4. Instead I am getting (see table). This the formula:
first year: B(1) = p* (1 + i) second year: B(2) = (p + B(1)) * (1 + i) third year: B(3) = (p + B(2)) * (1 + i) the t-th year: B(t) = (p + B(t-1)) * (1 + i)
Year | Principal | Balance |
---|---|---|
1 | 600.00 | 7200.00 |
2 | 7200.00 | 46800.00 |
3 | 46800.00 | 284400.00 |
4 | 284400.00 | 1710000.00 |
Code is:
table {
border-collapse: collapse;
width: 60%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
.error {
color: red;
text-align: center;
}
Investment Calculator
Annual Investment:
Annual Growth Rate:
Length of Investment (in years):
document.querySelector("#calculateButton").addEventListener("click", function() {
let p = parseFloat(document.querySelector("#pInput").value);
let i = parseFloat(document.querySelector("#iInput").value);
let t = parseFloat(document.querySelector("#tInput").value);
if (p <= 0 || i <= 0 || t <= 0) {
document.querySelector("#result").innerHTML = "
return;
}
let result = "
Year | Principal | Balance |
---|---|---|
" + year + " | " + principal.toFixed(2) + " | " + balance.toFixed(2) + " |
document.querySelector("#result").innerHTML = result;
});
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started