Built with blockbuilder.org
Last active
November 28, 2017 16:33
-
-
Save henryjameslau/829d8cb5bb6c047cfae2c18f30c38d7e to your computer and use it in GitHub Desktop.
student loan calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
var owe="hello!"; | |
var loan=0; | |
var loaninterest=0; | |
var loaninterestrate; | |
var salary=[0,0,0,14881,16955,19076,21542,23375,25440,26182,27324,29448,30308,31391,31384,32510,32532,33335,33960,33712,33907,35169,35401,35467,35444,35401,35040,35677,35225,35297,36279,35357,36034,36082,34870,35386,35922,35267,34337,33402,32770,32257,29292,28207,27139,23858,24458]; | |
var newsalary={}; | |
var repayments=0 | |
var salarygrowthrate=5.1; | |
var tuitionfees=9250; | |
var maintenanceloan=7000; | |
var lengthofcourse=3; | |
var owe={}; | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 2000) | |
for (var i = 0; i < 30; i++) { | |
//increase the loan while studying | |
if(i<lengthofcourse){loan=loan+tuitionfees+maintenanceloan} | |
// increase the salary with a growth rate | |
newsalary[i]=salary[i]*Math.pow((100+salarygrowthrate)/100,i) | |
console.log(salary[i],newsalary[i]) | |
//set the interest rate dependant on salary | |
if(newsalary[i]<21000){loaninterestrate=3.1;}else if(newsalary[i]>21000&&newsalary[i]<41000){loaninterestrate=3.1+((newsalary[i]-21000)/20000)*3.0}else if(newsalary[i]>41000){loaninterestrate=6.1}; | |
// while studying, interest rate is 6.1% | |
if(i<3){loaninterestrate=6.1} | |
//calculate the interest | |
loaninterest=loan*(loaninterestrate/100) | |
//console.log(loaninterest) | |
//add in the interest to the loan | |
loan=loan+loaninterest | |
//console.log(loaninterestrate) | |
//calculate the repayments | |
if(newsalary[i]>21000){repayments=(newsalary[i]-21000)*0.09} | |
//calculate how much you owe | |
loan=loan-repayments | |
console.log(loan,newsalary[i], loaninterest,loaninterestrate,repayments) | |
owe[i]=loan; | |
svg.append("text") | |
.text(loan) | |
.attr("y", 20+20*i) | |
.attr("x", 120) | |
.attr("font-size", 12) | |
.attr("font-family", "monospace") | |
svg.append("text") | |
.text(i) | |
.attr("y", 20+20*i) | |
.attr("x", 60) | |
.attr("font-size", 12) | |
.attr("font-family", "monospace") | |
} | |
console.log(owe) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment