Last active
October 1, 2018 13:03
-
-
Save actuallymentor/f0ae8f93a6ffc3b947c643df78dbd081 to your computer and use it in GitHub Desktop.
A simple script to calculate compound interest
This file contains hidden or 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
// Input it initial amount | |
// Interest as a number, e.g. 5% is 1.05 on a yearly basis | |
// Length as number of years | |
// Name of this calculation | |
// Addition determines whether the input variable is one time or a yearly contribution | |
function compound( input, interest, length, name, addition ) { | |
var accumulated = input | |
for ( i=0; i < length; i++ ) { | |
accumulated *= interest | |
if ( addition ){ | |
accumulated += input | |
} | |
} | |
console.log( name + ' will grow from ' + input + ' to ' + accumulated + ' at ' + interest + ' over ' + length + ' years' ) | |
} | |
compound( 500, 1.05, 40, 'sigarettes', true ) // How much money will a habit of cigarettes generate in retirement money? | |
compound( 750, 1.05, 40, 'coffee', true ) // How much money will a habit of coffee outside the house generate in retirement money? | |
compound( 3750, 1.05, 40, 'lunch', true ) // How much money will a habit of lunch out the house generate in retirement money? | |
compound( 500, 1.05, 40, '500', false ) | |
compound( 5000, 1.05, 40, '5000', false ) | |
compound( 5000, 1.07, 40, '5000', false ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment