Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda