JSFiddle - React, Tailwind, and code Playground

by cmoreira

HTML

Insert Sales Volume:
<input type="text" id="value_e" />
<a href="#" onclick="calculate_e();">Calculate</a><br />
Earnings: <span id="result_e"></span>

JavaScript

function calculate_e() {

    var value = document.getElementById('value_e').value;

    var total = 0;
    var income = 0;
    var breakpoint = 3750;
    var percentage = 0.5;

    while (total < value) {

        total++;
        income = income + percentage;

        if (total == breakpoint) {
            percentage = percentage + 0.01;
            breakpoint = breakpoint + breakpoint;
        }

    }

    document.getElementById('result_e').innerHTML = '$'+income.toFixed(2);
  
}