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

145
Visualizações
I'm trying to increase a value when clicking and value returning NaN

I've tried a lot of stuff, however I don't know any JavaScript. All of the JavaScript in the code is copied from stack overflow and other sources. The only thing I know how to use is HTML and I'm still very new. (it might also include some CSS which I also don't know at all)

The <!--<button id="bigButton" onclick="bigBottlePress()"><img src="Images/BigBottle.png"></button>--> is a failed thing so ignore it lol.

<html>
<head>
    <meta charset="utf-8">
    <title>Bottle Clicker</title>
</head>
<body>
<a href=# onclick="bigBottlePress()"><img src="Images/BigBottle.png" height="500"></a>
<!--<button id="bigButton" onclick="bigBottlePress()"><img src="Images/BigBottle.png"></button>-->
<br>
<br>
<input type="text" id="hydrationLevelDisplay" placeholder="Hydration Level: " disabled style= text-align:center>
<script>
    var hydrationLevel = 0
    function bigBottlePress() {
            var hydrationLevel = hydrationLevel + 1
            document.getElementById("hydrationLevelDisplay").value = "Hydration Level: " + hydrationLevel;
            document.title = "Hydration Level: " + hydrationLevel;
    }
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You have already declared hydrationLevel outside function, so don't need to redclare it. Just change,

var hydrationLevel = hydrationLevel + 1

to

hydrationLevel = hydrationLevel + 1
about 4 years ago · Juan Pablo Isaza Relatório

0

create a button -> id:btn create a result div or p or h1 -> id:hydrationLevel

select the button, add event listener

document.getElementById('btn').addEventListener('click', incrementLevel)
let hydrationCount = 0;

function incrementLevel() {
 hydrationCount += 1;
 document.getElementById('hydrationLevel').textContent = hydrationCount;
}

I'd encourage you to use event listeners this way. not inline that's why I provided this solution.

about 4 years ago · Juan Pablo Isaza Relatório
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