Skip to content

Instantly share code, notes, and snippets.

@special-character
Last active January 4, 2019 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save special-character/983b5e667216561010196c45f7456e63 to your computer and use it in GitHub Desktop.
Save special-character/983b5e667216561010196c45f7456e63 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/liboref
/*
* 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