-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCode.html
230 lines (222 loc) · 11.7 KB
/
Code.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>CSW Loans</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- Favicon -->
<link rel="icon" type="img/png" href="Assets/favicon.ico" />
<!-- Custom CSS -->
<link href="Content/styles.css" rel="stylesheet" />
<!-- Prism -->
<link href="Content/twilightprism.css" rel="stylesheet" />
<!-- Favicon -->
<link rel="icon" href="/Assets/favicon.ico" />
<!-- Nav bar css -->
<link href="Content/navbar.css" rel="stylesheet" />
</head>
<body>
<!-- NAV START -->
<nav class="navbar navbar-expand-lg bg-dark navbar-dark static-top">
<div class="container">
<!-- Navbar brand -->
<a class="navbar-brand" href="Index.html">CSW Loans</a>
<!-- Collapse button -->
<button class="navbar-toggler third-button" type="button" data-toggle="collapse" data-target="#navbarSupportedContent22"
aria-controls="navbarSupportedContent22" aria-expanded="false" aria-label="Toggle navigation">
<div class="animated-icon3"><span></span><span></span><span></span></div>
</button>
<!-- Collapsible content -->
<div class="collapse navbar-collapse" id="navbarSupportedContent22">
<!-- Links -->
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="Index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="Solve.html">Solution</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="Code.html">Code</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/mackenzieweaver/MortgageCalculator" target="_blank">Github</a>
</li>
</ul>
<!-- Links -->
</div>
<!-- Collapsible content -->
</div>
</nav>
<!-- NAV END -->
<!-- Header -->
<header class="py-5 mb-5">
<div class="container">
<div class="row h-100 align-items-center">
<div class="col-lg-12">
<h1 class="display-4 mt-5 mb-2">Code</h1>
<p class="lead mb-5">This project was largely built using the fundamentals of website development which are HTML, CSS, and JavaScript. Below you can find a brief explanation of how this program works since this is a scholistic project.</p>
</div>
</div>
</div>
</header>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col text-center">
<!--
<pre>
<code class="language-js line-numbers">// Calculate calls all other functions
function Calculate(loan, term, rate) {
// Rate includes decimal
rate = parseFloat(rate);
loan = parseInt(loan.replace(/$/, '').replace(/,/g, '').replace(/./, ''));
const table = document.getElementById("tbody");
if (isNaN(loan)) {
return;
}
// If there's already a table, remove it
while (table.firstChild) {
table.removeChild(table.firstChild);
}
// So money is rounded to 2 decimal places
let precision = 2;
// Total Principal = loan
document.getElementById("totalprincipal").innerHTML = `${accounting.formatMoney(loan)}`;
console.log(rate);
console.log(typeof (rate));
let totalMonthlyPayment;
if (isNaN(rate)) {
rate = 0;
totalMonthlyPayment = loan / term;
} else {
//Total Monthly Payment = (amount loaned) * (rate/1200) / (1 – (1 + rate/1200)(-Number of Months) )
// Equation 1
totalMonthlyPayment = (loan * (rate / 1200)) / (1 - Math.pow((1 + rate / 1200), -Math.abs(term)));
}
document.getElementById("monthlypayment").innerHTML = `${accounting.formatMoney(totalMonthlyPayment.toFixed(precision))}`;
// before the very first month equals the amount of the loan
// Equation 2
let remainingBalance = loan;
// Interest starting at zero
let totalInterest = 0;
for (let i = 1; i <= term; i++) {
//Equation 3
let interestPayment = remainingBalance * (rate / 1200);
totalInterest += interestPayment;
//Equation 4
let principalPayment = totalMonthlyPayment - interestPayment;
//Equation 5 remainingBalance = remainingBalance - principalPayment
remainingBalance -= principalPayment;
// Create row in table
let row = table.insertRow();
row.setAttribute("scope", "row");
//the table has a Header, Tbody, Row, Cell, and TextNode
let cell = row.insertCell();
let text = document.createTextNode(i.toString());
cell.appendChild(text);
// Payment
cell = row.insertCell();
text = document.createTextNode(accounting.formatMoney(totalMonthlyPayment.toFixed(precision)));
cell.appendChild(text);
// Principal
cell = row.insertCell();
text = document.createTextNode(accounting.formatMoney(principalPayment.toFixed(precision)));
cell.appendChild(text);
// Interest
cell = row.insertCell();
text = document.createTextNode(accounting.formatMoney(interestPayment.toFixed(precision)));
cell.appendChild(text);
// Total Interest
cell = row.insertCell();
text = document.createTextNode(accounting.formatMoney(totalInterest.toFixed(precision)));
cell.appendChild(text);
// Balance
cell = row.insertCell();
text = document.createTextNode(accounting.formatMoney(remainingBalance.toFixed(precision)));
cell.appendChild(text);
}
let totalCost = parseInt(loan) + totalInterest;
document.getElementById("totalinterest").innerHTML = `${accounting.formatMoney(totalInterest.toFixed(precision))}`;
document.getElementById("totalcost").innerHTML = `${accounting.formatMoney(totalCost)}`;
}
// Rate accepts decimals up to 3 places
function validateRate(rate) {
let char = rate.charAt(rate.length - 1);
if (char == '.') {
rate = rate.split('');
rate.splice(rate.length - 1, 1);
if (rate.indexOf(char) < 0) {
rate.splice(rate.length, 0, char);
}
rate = rate.join('');
document.getElementById("rate").value = rate;
}
if ((isNaN(parseInt(char)) && char != '.') || rate.length > 5) {
rate = rate.split('');
rate.splice(rate.length - 1, 1);
rate = rate.join('');
document.getElementById("rate").value = rate;
}
}
//Reset button
function Reset() {
document.getElementById("loan").value = "$100,000";
document.getElementById("rate").value = "3.92";
document.getElementById("term").value = "360";
document.getElementById("monthlypayment").innerText = "$0.00";
document.getElementById("totalprincipal").innerText = "$0.00";
document.getElementById("totalinterest").innerText = "$0.00";
document.getElementById("totalcost").innerText = "$0.00";
let table = document.getElementById("tbody");
// If there's already a table, remove it
while (table.firstChild) {
table.removeChild(table.firstChild);
}</code>
</pre>
-->
</div>
</div>
<div class="row">
<div class="col-12 mb-5">
<h2>Formulas Used</h2>
<hr class="mb-5">
<p>1.) Total Monthly Payment = (amount loaned) * (rate/1200) / (1 – (1 + rate/1200)(-Number of Months))</p>
<h6><code>let totalMonthlyPayment = (loan * (rate / 1200)) / (1 - Math.pow((1 + rate / 1200), -Math.abs(term)));</code></h6>
<br />
<p>2.) Remaining Balance before the very first month equals the amount of the loan.</p>
<h6><code>let remainingBalance = loan;</code></h6>
<br />
<p>3.) Interest Payment = Previous Remaining Balance * rate/1200</p>
<h6><code>let interestPayment = remainingBalance * (rate / 1200);</code></h6>
<br />
<p>4.) Principal Payment = Total Monthly Payment - Interest Payment</p>
<h6><code>let principalPayment = totalMonthlyPayment - interestPayment;</code></h6>
<br />
<p>5.) At end each month, Remaining Balance = Previous Remaining Balance - principal payments</p>
<h6><code>remainingBalance -= principalPayment;</code></h6>
</div>
</div>
</div>
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<p class="mb-0 pt-5 text-center text-white">Copyright © CSW Loans 2020 - 2022</p>
</div>
</footer>
<!-- Bootstrap core JavaScript -->
<script src="//code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="//cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<!-- Custom JS -->
<script src="Scripts/CustomJS.js"></script>
<script src="Scripts/accounting.min.js"></script>
<script src="Scripts/InputFormatting.js"></script>
<!-- Prism -->
<script src="Scripts/twilightprism.js"></script>
<!-- Custom JS toggles nav -->
<script src="Scripts/togglenav.js"></script>
</body>
</html>