Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
span element tag only changes 1 number instantly

I am trying to have the "ShackTot" variable automatically update on-screen when the "Buy Reputation" button is pressed.

It should work similarly to how the "Cash" variable decreases as the "Buy Shack" button is clicked where the "Cash" on-screen automatically decreases when the "Buy Shack" button is clicked.

The "ShackTot" variable does decrease as the "Buy Reputation" button is clicked but you need to click the "Buy Shack" button for it to update on-screen.

var Cash = 150000;

var ShackCost = 50;
var Shack = 0;
var ShackTot = 0;
var ShackTotCost1 = 50;
var ShackOut = 1;

var Reputation = 0;
var ReputationCost = 1;
var ReputationTot = 0;
var ReputationTotCost1 = 1;

function buyShack() {
  if (Cash >= ShackCost) {
    Cash = Cash - ShackCost;
    Shack = Shack + 1;
    ShackCost = Math.round(ShackCost * 1);
    ShackCount = Shack;
    ShackTotCost1 = ShackCost;

    document.getElementById("Cash").innerHTML = Cash;
    document.getElementById("ShackTot").innerHTML = ShackCount;
    // document.getElementById("ShackTotCost").innerHTML = ShackTotCost1;
  }
}

function buyReputation() {
  if (Shack >= ReputationCost) {
    Shack = Shack - ReputationCost;
    Reputation = Reputation + 1;
    ReputationCost = Math.round(ReputationCost * 1);
    ReputationCount = Reputation;
    ReputationTotCost1 = ReputationCost;
    ShackCount = Shack;

    document.getElementById("ReputationTot").innerHTML = ReputationCount;
    // document.getElementById("ReputationTotCost").innerHTML = ReputationTotCost1;
    document.getElementById("ShackTot").innerHTML = ShackCount;
  }
}
<h1>Cash: <span id="Cash">150000</span></h1>
<h1>Shacks: <span id="ShackTot">0</span></h1>
<h1>Reputation: <span id="ReputationTot">0</span></h1>

<button onclick="buyShack()">Buy Shack</button>
<button onclick="buyReputation()">Buy Reputation</button>

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda