DEV Community

Cover image for How I built a FIRE Age Calculator in Vanilla JS
NovusTools
NovusTools

Posted on • Originally published at novustools.com

How I built a FIRE Age Calculator in Vanilla JS

As tech professionals, achieving Financial Independence and Retiring Early (FIRE) is a huge goal. I wanted a quick, private way to track my FIRE number based on the 4% rule, so I built a clean, client-side FIRE Age Calculator.

The Approach

I built this using 100% Vanilla JS. Financial data is sensitive, so I made sure there are zero server calls. Everything stays in your browser.

Here is a quick look at the core loop calculating the time needed to reach the target portfolio:

function calculateFIRE(monthlyExpenses, currentSavings, monthlyInvestment, annualReturnRate) {
    const fireNumber = monthlyExpenses * 12 * 25; // The 4% safe withdrawal rule
    let months = 0;
    let portfolio = currentSavings;
    const monthlyRate = (annualReturnRate / 100) / 12;

    while (portfolio < fireNumber) {
        portfolio = (portfolio * (1 + monthlyRate)) + monthlyInvestment;
        months++;
    }

    return { 
        fireNumber: fireNumber, 
        yearsToFire: (months / 12).toFixed(1) 
    };
}
Enter fullscreen mode Exit fullscreen mode

Try it out

You can use the live tool for free here: FIRE Age Calculator

Let me know what you think or if you'd add any other variables to the calculation in the comments!

Top comments (0)