0

I am making a store in my Javascript Browser Game, I am I trying to change the text of a button every time I press it. I starts out as "Powerup (*** Points)" Or something like that, and the points increase each time I click on it, so the gameplay is balanced, but fun...

I want to change the buttons text to show the points, my code is:

document.getElementById("X10Thing").innerHTML = 'Buy X2 (10 Points)'
function buyX2() {
  if (derp > X2Cost) {
   Times1 = Times1 + 1;
   derp = derp - (X2Cost + 1);
   X2Cost = X2Cost + round((X2Cost / Times1));
   X2Cost2 = X2Cost + 1;
                        //This is the main problem//
   document.getElementById("X10Thing").innerHTML = 'Buy X2 (' + X2Cost2 + ' Points)'
  }
  }
<button type="button" onclick="buyX2()" id="X10Thing"></button>

And, when I have enough Derps (I haven't found a good name for the currency...) The button doesn't change, at all, or it will become a little button. Please Help...

Yatrix
  • 13,361
  • 16
  • 48
  • 78

1 Answers1

0

try using Math.round rather than just round.

document.getElementById("X10Thing").innerHTML = 'Buy X2 (10 Points)';

var derp = 10;
var X2Cost = 1;
var Times1 = 1;

function buyX2() {
    if (derp > X2Cost) {
        Times1 = Times1 + 1;
        derp = derp - (X2Cost + 1);
        X2Cost = X2Cost + Math.round((X2Cost / Times1));
        X2Cost2 = X2Cost + 1;
        //This is the main problem//
        document.getElementById("X10Thing").innerHTML = 'Buy X2 (' + X2Cost2 + ' Points)';
    }
}

buyX2();
Allen Tellez
  • 1,198
  • 1
  • 10
  • 14