Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!