JSFiddle - React, Tailwind, and code Playground

by Daedalus

HTML

<button id="calculate">Calculate</button>
<br />
<div id='debug'></div>

JavaScript

var tests = {
    0: {
        currentTotal: 850,
        originalTotal: 1000,
        experience: 150,
        expected: 1050
    },
    1: {
        currentTotal: 1000,
        originalTotal: 3000,
        experience: 300,
        expected: 1750
    },
    2: {
        currentTotal: 1500,
        originalTotal: 2000,
        experience: 300,
        expected: 2200
    },
    length: 3
};

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,
        bonus = 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) {
            bonus += plans[plan].bonus[bonus_i].bonus_val;
        }
        bonus_i++;
    }

    var remainder = 0;

    if ((current_total + (event_xp * bonus)) < until) {
        //remainder = event_xp - ((cap - current_total) / bonus);
        remainder = ((until - current_total) % bonus);
        current_total += ((event_xp - remainder) * bonus);
        current_total += remainder;
    }

    return current_total;
}

$(function () {
    $("#calculate").click(function () {
        $("#debug").html("");
        $.each(tests, function (i, v) {
            var ct = v.currentTotal,
                ot = v.originalTotal,
                xp = v.experience,
                expected = v.expected,
                output = test_xp(ct, ot,...