Skip to content

This is my project for JS #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 73 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Foundations</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p>Open up the console to check your work!</p>

<script src="index.js"></script>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>

</head>

<body class="container">
<div class="row">
<div class="span6">
<h1 align="center">JavaScript Foundations Mortgage Calculator</h1>
<form class="form-horizontal well" name="MortgageMinder" >
<div class="control-group">
<label class="control-label">House Price</label>
<div class="controls">
<input type="text" onchange="checkForZero(this)" onblur="checkForZero(this)" size="7" value="750000" name="price"></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Interest Rate</label>
<div class="controls">
<input type="text" onchange="checkForZero(this)" onblur="checkForZero(this)" size="4" value="6" name="ir"></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Years</label>
<div class="controls">
<input type="text" onchange="checkForZero(this)" onblur="checkForZero(this)" size="4" value="30" name="term">
</input>
</div>
</div>
<div class="control-group">
<label class="control-label">Down Payment</label>
<div class="controls">
<input type="text" size="7" onchange="calculatePayment(this.form)" value="0" name="dp">

</input>
</div>
</div>
<br/>
<div class="control-group">
<label class="control-label">Mortgage Principle</label>
<div class="controls">
<input type="text" size="7" placeholder="Automatically Calculated" name="principle">

</input>
</div>
</div>
<div class="control-group">
<label class="control-label">Total Payments</label>
<div class="controls">
<input type="text" size="6" placeholder="Your Number Of Payments Are" name="payments">

</input>
</div>
</div>
<div class="control-group">
<label class="control-label">Monthly Payment</label>
<div class="controls">
<input type="text" placeholder="Monthly Payments" size="7" name="pmt">
</input>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="button" class="btn btn-primary btn-large" onclick="cmdCalc_Click(this.form)" value="Calculate" name="cmdCalc">
</input>
</div>
</div>
</form>
<p> This is a project. Please refer to you bank for actual </p>
</div>
</div>
</body>
</html>
</html>
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,41 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:


/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */








function checkForZero(field) {
if (field.value == 0 || field.value.length == 0) {
alert ("This field can't be 0!");
field.focus(); }
else
calculatePayment(field.form);
}

function cmdCalc_Click(form) {
if (form.price.value == 0 || form.price.value.length == 0) {
alert ("The Price field can't be 0!");
form.price.focus(); }
else if (form.ir.value == 0 || form.ir.value.length == 0) {
alert ("The Interest Rate field can't be 0!");
form.ir.focus(); }
else if (form.term.value == 0 || form.term.value.length == 0) {
alert ("The Term field can't be 0!");
form.term.focus(); }
else
calculatePayment(form);
}

function calculatePayment(form) {
princ = form.price.value - form.dp.value;
intRate = (form.ir.value/100) / 12;
months = form.term.value * 12;
form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
form.principle.value = princ;
form.payments.value = months;
}