Last active
January 4, 2019 22:57
-
-
Save special-character/983b5e667216561010196c45f7456e63 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/liboref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A calculator for determining how much interest will be gained on an investment in a year | |
* Inputs: Principle, interest rate of the loan, additional amount invested every month, and the number of months to calculate interest for | |
*/ | |
const PRINCIPAL = 30000 | |
const INTEREST_RATE = .0139 | |
const ADDITIONS_PER_MONTH = 0 | |
const NUM_MONTHS = 12 | |
const calculateInterest = (principal, interestRate, additionsPerMonth, numMonths) => { | |
let accountSum = principal | |
let totalInterest = 0 | |
for(let i=0; i<numMonths; i++) { | |
const monthInterest = (accountSum * interestRate) * (1/12) | |
totalInterest += monthInterest | |
accountSum += monthInterest + additionsPerMonth | |
} | |
console.log('Account Sum: ' + accountSum) | |
console.log('Interest Gained: ' + totalInterest) | |
} | |
console.log('PRINCIPAL ' + PRINCIPAL + ' Interest rate ' + INTEREST_RATE + ' Additions per month ' + ADDITIONS_PER_MONTH) | |
calculateInterest(PRINCIPAL, INTEREST_RATE, ADDITIONS_PER_MONTH, NUM_MONTHS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment