Question
I have a question about some javascript I am writing. I am nearly done but can't get over the last hurdle. The calculator should read
I have a question about some javascript I am writing. I am nearly done but can't get over the last hurdle. The calculator should read out for each year year 1 - 630, year 2 - 1291.50, year 3 1986.08. This comes with the inputs of 600 for annual invest, 5 for growth , and 4 for length in years. The formula is At the end of the t-th year: B(t) = (p + B(t-1)) * (1 + i). annual investment (p), annual growth rate (i), and the length of investment (t).
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 for
Annual Investment:
Annual Growth Rate:
Length of Investment (in years):
// Your JavaScript code here
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