Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Last active December 11, 2015 16:48
Show Gist options
  • Save dhigginbotham/4630141 to your computer and use it in GitHub Desktop.
Save dhigginbotham/4630141 to your computer and use it in GitHub Desktop.
Loan Calculator yayQuery
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