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

91
Views
Multiplying changing variables in javascript and displaying

I'm trying to make the CPS Total: display the current total amount of Shacks multiplied by the value of the ShackOut value. Can somebody please help me achieve this? In this case, the base value of CPS Total should be 0 but should increase by 1 for each Shack purchased (by clicking the button). This number should update

<html>
<head>
  <script>
var Cash = 75;
var CPStot = 0;

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

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

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

setInterval(function() {
  Cash = Cash + Shack * ShackOut;
  document.getElementById("Cash").innerHTML = Cash;
}, 250);
  </script>
</head>

<body>
  <h1>
    Shacks: <span id="ShackTot">0</span><br> Cash: <span id="Cash">75</span><br>
    <button onclick="buyShack()" id="button">Click Me!</button><br> CPS Total: <span id="CPStotStart">0</span>
  </h1>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
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!