JSFiddle - React, Tailwind, and code Playground

by stevenkaspar

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<script>
var money = 200;
var maxMoney = 300;
var mps = 0;
$(document).ready(function() {
    updateCounters();
    var buy1 = new clicker(200, 50, 20, "buy1", true);
    if (buy1.addCreateNew === true) {
        buy1.createNew();
        $(newBuy).click(function() {
            buy1.buy();
        });
    }
    var buy2 = new clicker(300, 100, 50, "buy2", true);
    if (buy2.addCreateNew === true) {
        buy2.createNew();
        $(newBuy).click(function() {
            buy2.buy();
        });
    }
});

function updateCounters() {
    $(".money").text("money: " + money);
    $(".mps").text("money per sec: " + mps);
    $(".max").text("max money: " + maxMoney);
}
function clicker(addPrice, addPriceIncrement, addMps, addName, addCreateNew) {
    this.addPrice = addPrice;
    this.addPriceIncrement = addPriceIncrement;
    this.addMps = addMps;
    this.addName = addName;
    this.addCreateNew = addCreateNew;
}
clicker.prototype.createNew = function() {
    newBuy = $("<div></div>");
    $(newBuy).text(this.addName + " " + "plus" + " " + this.addMps + "mps:" + " " + this.addPrice + "m");
    $("body").append(newBuy);
};

clicker.prototype.buy = function() {
    if (money >= this.addPrice) {
        money -= this.addPrice;
        this.addPrice += this.addPriceIncrement;
        mps += this.addMps;
        updateCounters();
        var self = this;

        function max() {
            if (money < maxMoney) {
                money += self.addMps;
                updateCounters();
                setTimeout(max, 1000);
            }
        }
        setTimeout(max, 0);
        var buy_x = new clicker(200, 50, 20, "buy1", true);
        if (buy_x.addCreateNew === true) {
            buy_x.createNew();
            $(newBuy).click(function() {
               ...