Skip to content
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
11 changes: 11 additions & 0 deletions retirementCalc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Project Shift</title>
</head>
<body>
<script src="./retirementCalc.js"></script>
<!-- Content here -->
</body>
</html>
61 changes: 61 additions & 0 deletions retirementCalc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Developer Name: Ben Joyce
// Project Name: Retirement Calculator
// Date: 12/10/2019



const calcFunction = function (percentOfSalary, averageReturnRate, averageSalary, years) {


//Variables Declared
const percentARR = averageReturnRate * 100;
const pPOS = percentOfSalary * 100;
const taxRate = 0.25;
const lessTaxRate = 1 - taxRate;
const salaryToSave = averageSalary * lessTaxRate * percentOfSalary;
let total = 0;



//function that calulates the balance at the end of one year

const calcEndBalance = function (toSave, interest) {
const interestMultiplier = (1 + interest);

for (let i = 0; i < years; i++) {
if (i > 0) {
total *= interestMultiplier;
}

total += toSave;

};

return total;

};

// IIFE: set equal to a function being invoked (sets a variable that requires multiple operations)
const endBalance = function() {
let balance = calcEndBalance(salaryToSave, averageReturnRate);
balance = Math.round(balance);
balance = thousands_separators(balance);
return balance;
}();

function thousands_separators(num) {
var num_parts = num.toString().split(".");
num_parts[0] = num_parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return num_parts.join(".");
}

console.log(`With an average salary of $${thousands_separators(averageSalary)} over the next ${years} years, you will have $${endBalance} if you invest ${pPOS}% of your post-tax income with an ${percentARR}% return.`)
};




calcFunction(.20, .08, 50000, 20);