Question: Having issue with javascript still. This code gives the wrong output. It gives: Year Principal Balance 1 600.00 7200.00 2 7200.00 46800.00 3 46800.00 284400.00
Having issue with javascript still. This code gives the wrong output.
It gives:
| Year | Principal | Balance |
|---|---|---|
| 1 | 600.00 | 7200.00 |
| 2 | 7200.00 | 46800.00 |
| 3 | 46800.00 | 284400.00 |
| 4 | 284400.00 | 1710000.00 |
When it should give:
| Year | Principal | Balance |
|---|---|---|
| 1 | 600.00 | 630.00 |
| 2 | 1200.00 | 1291.50 |
| 3 | 1800.00 | 1986.08 |
| 4 | 2400.00 | 2715.38 |
Help would be appreciated.
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 123
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
Get step-by-step solutions from verified subject matter experts
