Last active
December 11, 2015 16:48
-
-
Save dhigginbotham/4630141 to your computer and use it in GitHub Desktop.
Loan Calculator yayQuery
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
var s, | |
LoanCalculator = { | |
settings: { | |
apr: jQuery("#lc_interest_rate").val(), | |
term: jQuery("#lc_term_length").val(), | |
price: jQuery("#lc_amount").val(), | |
button: jQuery("#lc_calculate"), | |
amount: 0, | |
result: jQuery("#lc_payments") | |
}, | |
init: function() { | |
s = this.settings; | |
this.bindUIActions(); | |
}, | |
bindUIActions: function() { | |
s.button.live("click", function() { | |
LoanCalculator.calculatePayment(); | |
jQuery(s.result).val(Math.ceil(s.amount) + '.00'); | |
}); | |
}, | |
calculatePayment: function() { | |
//payment = principle * monthly interest/(1 - (1/(1+MonthlyInterest)*Months)) | |
s.amount = s.price * s.apr / (1 - (Math.pow(1/(1 + s.apr), s.term))); | |
} | |
} | |
jQuery(document).ready (function() { | |
LoanCalculator.init(); | |
console.log('Initializing Calculator...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment