mirror of
https://github.com/Raghu-Ch/ES6-Handson.git
synced 2026-02-10 04:33:02 -05:00
Initial commit
This commit is contained in:
30
build/main.bundle.js
Normal file
30
build/main.bundle.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var calculateMonthlyPayment = function calculateMonthlyPayment(principal, years, rate) {
|
||||
var monthlyRate = 0;
|
||||
if (rate) {
|
||||
monthlyRate = rate / 100 / 12;
|
||||
}
|
||||
var monthlyPayment = principal * monthlyRate / (1 - Math.pow(1 / (1 + monthlyRate), years * 12));
|
||||
return { principal: principal, years: years, rate: rate, monthlyPayment: monthlyPayment, monthlyRate: monthlyRate };
|
||||
// Creating Objects from Variables ## ES6
|
||||
// shorted for the following ES5 syntax
|
||||
// return { principal: principal,
|
||||
// years: years,
|
||||
// rate: rate,
|
||||
// monthlyPayment: monthlyPayment,
|
||||
// monthlyRate: monthlyRate };
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
document.getElementById("monthlyPayment").innerHTML = monthlyPayment.toFixed(2);
|
||||
document.getElementById("monthlyRate").innerHTML = (monthlyRate * 100).toFixed(2);
|
||||
});
|
||||
Reference in New Issue
Block a user