-
Notifications
You must be signed in to change notification settings - Fork 0
/
mortgage.js
80 lines (75 loc) · 2.1 KB
/
mortgage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
$( function() {
//Down Payment
var handle = $( "#varry" );
$( "#slider" ).slider({
min: 0,
max: 100000,
create: function() {
handle.text( $( this ).slider( "value" ) );
},
slide: function( event, ui ) {
handle.text( ui.value );
}
});
//Interest
var handle1 = $( "#int_label" );
$( "#interest" ).slider({
min: 5,
max: 20,
create: function() {
handle1.text( $( this ).slider( "value" ) );
},
slide: function( event, ui ) {
handle1.text( ui.value );
}
});
//Years
var handle2 = $( "#yrs_label" );
$( "#years" ).slider({
min: 0,
max: 30,
create: function() {
handle2.text( $( this ).slider( "value" ) );
},
slide: function( event, ui ) {
handle2.text( ui.value );
}
});
//Calculate
var property_value = $("#user_input").val(),
down_payment = $("#varry").text(),
interest = $( "#int_label" ).text(),
yrs = $( "#yrs_label" ).text();
//Detect and take user input
$("#user_input").change(function det_user_input(){
property_value = $("#user_input").val()
}
);
//Detect and take DownPayment
$( "#slider" ).on( "slide", function( event, ui ) {
down_payment = $( "#varry" ).text()
}
);
//Detect and take interest slider value
$( "#interest" ).on( "slide", function( event, ui ) {
interest = $( "#int_label" ).text()
}
);
//Detect and take no of years
$( "#years" ).on( "slide", function( event, ui ) {
yrs = $( "#yrs_label" ).text()
}
);
//Main Calculator
$("#button").click(function gen(){
interest = $( "#int_label" ).text();
down_payment = $( "#varry" ).text();
yrs = $( "#yrs_label" ).text();
var m_i = interest/1200
var m_no = yrs*12
var mortage = property_value - down_payment
var m_p = (mortage*Math.pow((1+m_i),m_no)*m_i)/(Math.pow((1+m_i),m_no)-1)
$("#amount_monthly").text(m_p.toFixed(2));
}
)
} );