diff --git a/build/main.bundle.js b/build/main.bundle.js index e99b19c..e8015d2 100644 --- a/build/main.bundle.js +++ b/build/main.bundle.js @@ -1,4 +1,77 @@ -'use strict'; +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + var calculateMonthlyPayment = function calculateMonthlyPayment(principal, years, rate) { var monthlyRate = 0; @@ -15,16 +88,45 @@ var calculateMonthlyPayment = function calculateMonthlyPayment(principal, years, // monthlyPayment: monthlyPayment, // monthlyRate: monthlyRate }; }; +var calculateAmortization = function calculateAmortization(principal, years, rate) { + var _calculateMonthlyPaym = calculateMonthlyPayment(principal, years, rate), + monthlyRate = _calculateMonthlyPaym.monthlyRate, + monthlyPayment = _calculateMonthlyPaym.monthlyPayment; + + var balance = principal; + var amortization = []; + for (var y = 0; y < years; y++) { + var interestY = 0; // Interest payment for year y + var principalY = 0; // principal payment for year y + for (var m = 0; m < 12; m++) { + var interestM = balance * monthlyRate; // Interest payment for month m + var principalM = monthlyPayment - interestM; //principal payment for month m + interestY = interestY + interestM; + principalY = principalY + principalM; + balance = balance - principalM; + } + amortization.push({ principalY: principalY, interestY: interestY, balance: balance }); + } + return { monthlyPayment: monthlyPayment, monthlyRate: monthlyRate, amortization: amortization }; +}; 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 _calculateMonthlyPaym = calculateMonthlyPayment(principal, years, rate), - monthlyPayment = _calculateMonthlyPaym.monthlyPayment, - monthlyRate = _calculateMonthlyPaym.monthlyRate; + var _calculateAmortizatio = calculateAmortization(principal, years, rate), + monthlyPayment = _calculateAmortizatio.monthlyPayment, + monthlyRate = _calculateAmortizatio.monthlyRate, + amortization = _calculateAmortizatio.amortization; document.getElementById("monthlyPayment").innerHTML = monthlyPayment.toFixed(2); document.getElementById("monthlyRate").innerHTML = (monthlyRate * 100).toFixed(2); + amortization.forEach(function (month) { + return console.log(month); + }); }); + +/***/ }) +/******/ ]); +//# sourceMappingURL=main.bundle.js.map \ No newline at end of file diff --git a/build/main.bundle.js.map b/build/main.bundle.js.map new file mode 100644 index 0000000..47c9fe8 --- /dev/null +++ b/build/main.bundle.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/bootstrap 08364d4a2409405e582d","webpack:///./js/main.js"],"names":["calculateMonthlyPayment","principal","years","rate","monthlyRate","monthlyPayment","Math","pow","calculateAmortization","balance","amortization","y","interestY","principalY","m","interestM","principalM","push","document","getElementById","addEventListener","value","innerHTML","toFixed","forEach","console","log","month"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;;;AChEA,IAAIA,0BAA0B,SAA1BA,uBAA0B,CAACC,SAAD,EAAYC,KAAZ,EAAmBC,IAAnB,EAA4B;AACtD,QAAIC,cAAc,CAAlB;AACA,QAAID,IAAJ,EAAU;AACNC,sBAAcD,OAAO,GAAP,GAAa,EAA3B;AACH;AACD,QAAIE,iBAAiBJ,YAAYG,WAAZ,IAA2B,IAAKE,KAAKC,GAAL,CAAS,KAAK,IAAIH,WAAT,CAAT,EAAgCF,QAAQ,EAAxC,CAAhC,CAArB;AACA,WAAO,EAACD,oBAAD,EAAYC,YAAZ,EAAmBC,UAAnB,EAAyBE,8BAAzB,EAAyCD,wBAAzC,EAAP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACH,CAdD;AAeA,IAAII,wBAAwB,SAAxBA,qBAAwB,CAACP,SAAD,EAAYC,KAAZ,EAAmBC,IAAnB,EAA4B;AAAA,gCAChBH,wBAAwBC,SAAxB,EAAmCC,KAAnC,EAA0CC,IAA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,GAAsDjB,eAAekB,OAAf,CAAuB,CAAvB,CAAtD;AACAL,aAASC,cAAT,CAAwB,aAAxB,EAAuCG,SAAvC,GAAmD,CAAClB,cAAY,GAAb,EAAkBmB,OAAlB,CAA0B,CAA1B,CAAnD;AACAb,iBAAac,OAAb,CAAqB;AAAA,eAASC,QAAQC,GAAR,CAAYC,KAAZ,CAAT;AAAA,KAArB;AACH,CARD,E","file":"main.bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 08364d4a2409405e582d","let calculateMonthlyPayment = (principal, years, rate) => {\r\n let monthlyRate = 0;\r\n if (rate) {\r\n monthlyRate = rate / 100 / 12;\r\n }\r\n let monthlyPayment = principal * monthlyRate / (1 - (Math.pow(1 / (1 + monthlyRate), years * 12)));\r\n return {principal, years, rate, monthlyPayment, monthlyRate};\r\n // Creating Objects from Variables ## ES6\r\n // shorted for the following ES5 syntax\r\n // return { principal: principal,\r\n // years: years,\r\n // rate: rate,\r\n // monthlyPayment: monthlyPayment,\r\n // monthlyRate: monthlyRate };\r\n};\r\nlet calculateAmortization = (principal, years, rate) => {\r\n let {monthlyRate, monthlyPayment} = calculateMonthlyPayment(principal, years, rate);\r\n let balance = principal;\r\n let amortization = [];\r\n for (let y=0; y {\r\n let principal = document.getElementById(\"principal\").value;\r\n let years = document.getElementById(\"years\").value;\r\n let rate = document.getElementById(\"rate\").value;\r\n let {monthlyPayment, monthlyRate, amortization} = calculateAmortization(principal, years, rate);\r\n document.getElementById(\"monthlyPayment\").innerHTML = monthlyPayment.toFixed(2);\r\n document.getElementById(\"monthlyRate\").innerHTML = (monthlyRate*100).toFixed(2);\r\n amortization.forEach(month => console.log(month));\r\n});\r\n\n\n\n// WEBPACK FOOTER //\n// ./js/main.js"],"sourceRoot":""} \ No newline at end of file diff --git a/js/main.js b/js/main.js index d9d3ea0..1f4f907 100644 --- a/js/main.js +++ b/js/main.js @@ -1,4 +1,4 @@ -let calculateMonthlyPayment = function (principal, years, rate) { +let calculateMonthlyPayment = (principal, years, rate) => { let monthlyRate = 0; if (rate) { monthlyRate = rate / 100 / 12; @@ -13,12 +13,31 @@ let calculateMonthlyPayment = function (principal, years, rate) { // monthlyPayment: monthlyPayment, // monthlyRate: monthlyRate }; }; +let calculateAmortization = (principal, years, rate) => { + let {monthlyRate, monthlyPayment} = calculateMonthlyPayment(principal, years, rate); + let balance = 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 {monthlyPayment, monthlyRate} = calculateMonthlyPayment(principal, years, rate); + let {monthlyPayment, monthlyRate, amortization} = calculateAmortization(principal, years, rate); document.getElementById("monthlyPayment").innerHTML = monthlyPayment.toFixed(2); document.getElementById("monthlyRate").innerHTML = (monthlyRate*100).toFixed(2); + amortization.forEach(month => console.log(month)); }); diff --git a/package.json b/package.json index 9e4b57d..c8fd8f5 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,17 @@ "main": "main.js", "scripts": { "babel": "babel --presets es2015 js/main.js -o build/main.bundle.js", - "start": "http-server -p 7001" + "start": "http-server -p 7000", + "webpack": "webpack" }, "author": "RaghuJS", "license": "MIT", "devDependencies": { "babel-cli": "^6.22.2", "babel-core": "^6.22.1", + "babel-loader": "^6.2.10", "babel-preset-es2015": "^6.22.0", - "http-server": "^0.9.0" + "http-server": "^0.9.0", + "webpack": "^2.2.1" } } diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..fc314e7 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,23 @@ +var path = require('path'); +var webpack = require('webpack'); + +module.exports = { + entry: './js/main.js', + output: { + path: path.resolve(__dirname, 'build'), + filename: 'main.bundle.js' + }, + module: { + loaders: [ + { + test: /\.js$/, + loader: 'babel-loader', + query: { presets: ['es2015']} + } + ] + }, + stats: { + colors: true + }, + devtool: 'source-map' +};