From 29156024c3b7d6efb55506182d694757fb37dc33 Mon Sep 17 00:00:00 2001 From: Shorttriptomars Date: Thu, 7 Sep 2017 21:01:40 -0400 Subject: [PATCH 1/3] Add files via upload --- js/main.js | 64 ++++++++++++++++++++++++++++++++--------- js/mortgage2.js | 35 ++++++++++++++++++++++ js/rate-service-mock.js | 20 +++++++++++++ 3 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 js/mortgage2.js create mode 100644 js/rate-service-mock.js diff --git a/js/main.js b/js/main.js index 6565a8969..9ab07c361 100644 --- a/js/main.js +++ b/js/main.js @@ -1,15 +1,53 @@ -var calculateMonthlyPayment = function (principal, years, rate) { - if (rate) { - var monthlyRate = rate / 100 / 12; +import Mortgage from './mortgage2'; + + get amortization() { + let monthlyPayment = this.monthlyPayment; + let monthlyRate = this.rate / 100 / 12; + let balance = this.principal; + let amortization = []; + for (let y=0; y { + let principal = document.getElementById("principal").value; + let years = document.getElementById("years").value; + let rate = document.getElementById("rate").value; + let mortgage = new Mortgage(principal, years, rate); + document.getElementById("monthlyPayment").innerHTML = mortgage.monthlyPayment.toFixed(2); + document.getElementById("monthlyRate").innerHTML = (rate / 12).toFixed(2); + let html = ""; + mortgage.amortization.forEach((year, index) => html += ` + + ${index + 1} + ${Math.round(year.principalY)} + +
+
+
+
+
+
+ + ${Math.round(year.interestY)} + ${Math.round(year.balance)} + + `); + document.getElementById("amortization").innerHTML = html; +}); -document.getElementById('calcBtn').addEventListener('click', function () { - var principal = document.getElementById("principal").value; - var years = document.getElementById("years").value; - var rate = document.getElementById("rate").value; - var monthlyPayment = calculateMonthlyPayment(principal, years, rate); - document.getElementById("monthlyPayment").innerHTML = monthlyPayment.toFixed(2); -}); \ No newline at end of file diff --git a/js/mortgage2.js b/js/mortgage2.js new file mode 100644 index 000000000..dd11ee8c6 --- /dev/null +++ b/js/mortgage2.js @@ -0,0 +1,35 @@ +export default class Mortgage { + + constructor(principal, years, rate) { + this.principal = principal; + this.years = years; + this.rate = rate; + } + + get monthlyPayment() { + let monthlyRate = this.rate / 100 / 12; + return this.principal * monthlyRate / (1 - (Math.pow(1/(1 + monthlyRate), + this.years * 12))); + } + + get amortization() { + let monthlyPayment = this.monthlyPayment; + let monthlyRate = this.rate / 100 / 12; + let balance = this.principal; + let amortization = []; + for (let y=0; y new Promise((resolve, reject) => { + if (rates) { + resolve(rates); + } else { + reject("No rates"); + } +}); From 892c80458aabba4abdf6ca2782a95229b08c3a23 Mon Sep 17 00:00:00 2001 From: Shorttriptomars Date: Thu, 7 Sep 2017 21:02:36 -0400 Subject: [PATCH 2/3] Update index.html --- index.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 0364f0343..15c34b577 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,7 @@ +

Mortgage Calculator

@@ -29,7 +30,9 @@

Mortgage Calculator

Monthly Payment:

+

Monthly Rate:

+
- + - \ No newline at end of file + From 3bb0da9eede3f14ed29de0d49f6e711861796a98 Mon Sep 17 00:00:00 2001 From: Shorttriptomars Date: Thu, 7 Sep 2017 21:05:08 -0400 Subject: [PATCH 3/3] Add files via upload --- mortgage.js | 28 +++++++++++++++++++++++++++ npm-debug.log | 48 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 21 +++++++++++++++++++++ ratefinder.html | 10 ++++++++++ ratefinder.js | 9 +++++++++ webpack.config.js | 28 +++++++++++++++++++++++++++ 6 files changed, 144 insertions(+) create mode 100644 mortgage.js create mode 100644 npm-debug.log create mode 100644 package.json create mode 100644 ratefinder.html create mode 100644 ratefinder.js create mode 100644 webpack.config.js diff --git a/mortgage.js b/mortgage.js new file mode 100644 index 000000000..6c17e8e1c --- /dev/null +++ b/mortgage.js @@ -0,0 +1,28 @@ +export let calculateMonthlyPayment = (principal, years, rate) => { + let monthlyRate = 0; + if (rate) { + monthlyRate = rate / 100 / 12; + } + let monthlyPayment = principal * monthlyRate / (1 - (Math.pow(1/(1 + monthlyRate), + years * 12))); + return {principal, years, rate, monthlyPayment, monthlyRate}; +}; + +export let calculateAmortization = (principal, years, rate) => { + let {monthlyRate, monthlyPayment} = calculateMonthlyPayment(principal, years, rate); + let balance = principal; + let amortization = []; + for (let y=0; y (/Users/sushma/.nvm/versions/node/v6.11.0/lib/node_modules/npm/lib/utils/lifecycle.js:255:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (/Users/sushma/.nvm/versions/node/v6.11.0/lib/node_modules/npm/lib/utils/spawn.js:40:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:891:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) +15 verbose pkgid es6-tutorial-master@1.0.0 +16 verbose cwd /Users/sushma/Downloads/es6-tutorial-master +17 error Darwin 16.7.0 +18 error argv "/Users/sushma/.nvm/versions/node/v6.11.0/bin/node" "/Users/sushma/.nvm/versions/node/v6.11.0/bin/npm" "run" "webpack" +19 error node v6.11.0 +20 error npm v3.10.10 +21 error code ELIFECYCLE +22 error es6-tutorial-master@1.0.0 webpack: `webpack` +22 error Exit status 2 +23 error Failed at the es6-tutorial-master@1.0.0 webpack script 'webpack'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the es6-tutorial-master package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error webpack +23 error You can get information on how to open an issue for this project with: +23 error npm bugs es6-tutorial-master +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls es6-tutorial-master +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json new file mode 100644 index 000000000..7045e26f7 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "es6-tutorial-master", + "version": "1.0.0", + "description": "Start the tutorial [here](http://ccoenraets.github.io/es6-tutorial).", + "main": "index.js", + "scripts": { + "babel": "babel --presets es2015 js/main.js -o build/main.bundle.js", + "start": "http-server", + "webpack": "webpack" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "babel-cli": "^6.26.0", + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-preset-es2015": "^6.24.1", + "http-server": "^0.10.0", + "webpack": "^3.5.6" + } +} diff --git a/ratefinder.html b/ratefinder.html new file mode 100644 index 000000000..123a71b35 --- /dev/null +++ b/ratefinder.html @@ -0,0 +1,10 @@ + + + + + + +
+ + + \ No newline at end of file diff --git a/ratefinder.js b/ratefinder.js new file mode 100644 index 000000000..ca5272497 --- /dev/null +++ b/ratefinder.js @@ -0,0 +1,9 @@ +import * as service from './rate-service-mock'; + +service.findAll() + .then(rates => { + let html = ''; + rates.forEach(rate => html += `${rate.name}${rate.years}${rate.rate}%`); + document.getElementById("rates").innerHTML = html; + }) + .catch(e => console.log(e)); \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 000000000..012425076 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,28 @@ +var path = require('path'); + var webpack = require('webpack'); + + module.exports = { + entry: { + app: './js/main.js', + ratefinder: './js/ratefinder.js' +}, +output: { + path: path.resolve(__dirname, 'build'), + filename: '[name].bundle.js' +}, + module: { + loaders: [ + { + test: /\.js$/, + loader: 'babel-loader', + query: { + presets: ['es2015'] + } + } + ] + }, + stats: { + colors: true + }, + devtool: 'source-map' + }; \ No newline at end of file