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

220
Vistas
Weird behavior with +1 Button

I made a simple +1 Button-Game:

var money = 0;

function addOne() {
    money++;
    document.getElementById("money").innerHTML = money;
}

window.setInterval(function(){
 if(document.getElementById("money").innerHTML >= "50"){
    document.getElementById("timesTwoButtonShop").disabled = false;
  } else {
    document.getElementById("timesTwoButtonShop").disabled = true;
  } 
}, 1);
* {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">

<p>Money: <b id="money">0</b><b>$</b></p>

<button onclick="addOne();">+1$</button>

<br><br>

<h1>Shop</h1>
<button id="timesTwoButtonShop">2x for 50$</button>

I made it so that if the money is over or fifty then the 2x for 50$ button will be enabled. But when the money is between $6-$9 the button is somehow enabled. I really don't know how to fix this.

Thanks in advance and have a nice day

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Add a parseInt so it isn't string comparison OR use money which is already an int

var money = 0;

function addOne() {
    money++;
    document.getElementById("money").innerHTML = money;
}

window.setInterval(function(){
 // if (money>=50) {
 if(parseInt(document.getElementById("money").innerHTML) >= 50){
    document.getElementById("timesTwoButtonShop").disabled = false;
  } else {
    document.getElementById("timesTwoButtonShop").disabled = true;
  } 
}, 1);
* {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">

<p>Money: <b id="money">0</b><b>$</b></p>

<button onclick="addOne();">+1$</button>

<br><br>

<h1>Shop</h1>
<button id="timesTwoButtonShop">2x for 50$</button>

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