I have signed three loans in my life. I regretted two of them within a year. After the third, I made a rule: never sign a loan without modeling it in code first. The math is so small that a junior dev can write it in an afternoon, but the discipline of running it before the dotted line has saved me real money since. This post is the simulator I use, in roughly thirty lines, plus the three questions I ask it before agreeing to anything. The amortization formula, in code A fixed-rate loan is just a stream of payments where each one pays this month's interest first and the rest of it goes to principal. So you only need two helpers: function monthlyPayment ({ principal , annualRate , years }) { const r = annualRate / 12 ; const n = years * 12 ; return ( principal * r ) / ( 1 - Math .…