Skip to content

Commit 622044f

Browse files
committed
add lc js
1 parent 1fb6dfd commit 622044f

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

.floo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"url": "https://floobits.com/contolini/owning-a-home"
3+
}

.flooignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#*
2+
*.o
3+
*.pyc
4+
*~
5+
extern/
6+
node_modules/
7+
tmp
8+
vendor/
9+
src/vendor
10+
src/fonts
11+
static/fonts/
12+
dist/*
13+
static/*
14+
test/compiled_tests.js

src/js/modules/loan-comparison.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var debounce = require('debounce');
2+
var cost = require('overall-loan-cost');
3+
var formatUSD = require('format-usd');
4+
var unFormatUSD = require('unformat-usd');
5+
var isMoney = require('is-money-usd');
6+
var amortize = require('amortize');
7+
8+
function updateComparisons() {
9+
10+
var $monthly = $('#monthly-payment span'),
11+
$overall = $('#overall-costs span'),
12+
loanInfo = getLoanInfo(),
13+
costs = calcCosts( loanInfo );
14+
15+
$monthly.text( formatUSD(costs.monthlyPayment) );
16+
$overall.text( formatUSD(costs.overallCost) );
17+
18+
}
19+
20+
function getLoanInfo() {
21+
22+
function _sanitizeMoney( val ) {
23+
return isMoney( val ) ? unFormatUSD( val ) : 0;
24+
}
25+
26+
return {
27+
location: $('#location').val(),
28+
creditScore: $('#credit-score-select').val(),
29+
amountBorrowed: _sanitizeMoney( $('#house-price-input').val() - $('#down-payment-input').val() ),
30+
rateStructure: $('#rate-structure-select').val(),
31+
termLength: $('#loan-term-select').val(),
32+
loanType: $('#loan-type-select').val(),
33+
armType: $('#arm-type-select').val(),
34+
rate: $('#interest-rate-select').val()
35+
};
36+
37+
}
38+
39+
/**
40+
* Calculate loan costs given loan details provided by the user.
41+
* @return {object} monthly payment and overall cost of the loan
42+
*/
43+
function calcCosts( opts ) {
44+
45+
var loan,
46+
overall;
47+
48+
opts = opts || {};
49+
50+
loan = amortize({
51+
amount: opts.amountBorrowed,
52+
rate: opts.rate,
53+
totalTerm: opts.termLength,
54+
amortizeTerm: 60
55+
});
56+
57+
overall = cost({
58+
amountBorrowed: opts.amountBorrowed,
59+
rate: opts.rate,
60+
totalTerm: opts.termLength,
61+
});
62+
63+
return {
64+
monthlyPayment: loan.payment,
65+
overallCosts: overall.overallCost
66+
};
67+
68+
}
69+
70+
$('.comparisons').on( 'change', '.recalc', updateComparisons );

0 commit comments

Comments
 (0)