JSFiddle - React, Tailwind, and code Playground

by Daedalus

HTML

<input id="ct" placeholder="current total" />
<br />
<input id="ot" placeholder="original total" />
<br />
<input id="xp" placeholder="event exp" />
<br />
<button id="calculate">Calculate</button>
<br />
<span id='blah'></span>

JavaScript

function test_xp(ct, ot, xp) {
    var current_total = ct,
        original_total = ot,
        event_xp = xp,
        plans = {
            C: {
                mod: 1,
                until: 0
            },
            B: {
                mod: 1.5,
                until: original_total
            },
            A: {
                mod: 2,
                until: original_total,
                bonus: [{
                    bonus_val: 0.5,
                    bonus_until: (original_total < 2000 ? original_total + 500 : 2000)
                }]
            }
        },
        plan = "A",
        until = plans[plan].until,
        mod = plans[plan].mod,
        bonus_i = 0;

    while (current_total <= until && bonus_i < plans[plan].bonus.length) {
        until = plans[plan].bonus[bonus_i].bonus_until;
        if (current_total <= until) {
            mod += plans[plan].bonus[bonus_i].bonus_val;
        }
        bonus_i++;
    }
    console.log(mod);

    var cap = until,
        bonus = mod,
        remainder = 0;
    
    if ((current_total + (event_xp * bonus)) < cap) {
        remainder = event_xp - ((cap - current_total) / bonus);
        current_total += ((event_xp - remainder) * bonus);
        current_total += remainder;
    }

    var new_event_exp = current_total;

    document.getElementById('blah').innerHTML = new_event_exp;
}

$(function () {
    $("#calculate").click(function () {
        var ct = parseInt($("#ct").val(), 10),
            ot = parseInt($("#ot").val(), 10), 
            xp = parseInt($("#xp").val(), 10)
        test_xp(ct,ot,xp);
    });
});