Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 1FahadShakeel/ceddd7c74f0675ac351985756cc6950d to your computer and use it in GitHub Desktop.
Save 1FahadShakeel/ceddd7c74f0675ac351985756cc6950d to your computer and use it in GitHub Desktop.
compound interest with regular intervals
let princ = 10000; // start deposit
let add = 500; // monthly deposit (need plus it every year)
let rate = 0.06; // interest rate divided to create decimal
let months = (41 * 12); //41 years of monthly contributions
for (let i = 1; i <= months; i++) {
princ += princ * (rate / 12);
princ += add;
console.log(princ);
}
console.log(princ.toFixed(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment