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

147
Views
Javascript Clicker Game no funciona / El botón de clic no funciona

Estoy tratando de hacer un juego clicker básico en JS. Pero hay un problema.

Intenté hacer un clicker 2x, que es el juego que te preguntará si quieres comprar un clicker 2x cuando alcances los 100 clics. 2x clics básicamente le darán 2x clics.

Sin embargo, creo que rompió todo el código ya que el botón de clic no está dando ningún clic.

Aquí están los códigos:

JS:

 let clickCount = 0; let clickBoost = false; document.getElementById("clickButton").onclick = function(){ clickCount +=1; document.getElementById("clickCounter").innerHTML = clickCount; if (clickCount += 100){ let boostyorn = prompt("You have more clicks than 100." + "\n" + "\n" + "Do you wanna buy 2x Clicks?" + "\n" + "(Y/N)") if (boostyorn == "Y"){ document.getElementById("clickCounter").innerHTML = clickCount - 100; clickBoost = true; } else{ alert("You didn't bought 2x Clicks.") } } if (clickBoost == true) { document.getElementById("clickButton").onclick = function () { clickCount += 2; document.getElementById("clickCounter").innerHTML = clickCount; } }

}

HTML:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Clicker</title> <link rel="stylesheet" href="style.css"> </head> <body> <label id= "clickCounter">0</label><br> <center><button id= "clickButton">Click</button></center> <label id= "clickBoost" <script src="index.js"></script> </body> </html>

CSS:

 #clickCounter{ display: block; text-align: center; font-size: 150px; } #clickButton{ display: block; text-align: center; font-size: 100px; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

bien, hay dos errores que puedo encontrar. El primero que solucionará su problema general es un } faltante al final de su código.

el segundo problema ("error") es el restablecimiento de su cuenta de clics. hasta ahora entiendo que quieres ponerlo en cero a la derecha. por lo tanto, establece la variable en cero después de que el usuario responda "Y" o resta 100 antes de asignarlo a su HTML interno.

 let clickCount = 0; let clickBoost = false; document.getElementById("clickButton").onclick = function(){ clickCount +=1; document.getElementById("clickCounter").innerHTML = clickCount; if (clickCount === 100){ let boostyorn = prompt("You have more clicks than 100." + "\n" + "\n" + "Do you wanna buy 2x Clicks?" + "\n" + "(Y/N)") if (boostyorn == "Y"){ clickCount = clickCount - 100; document.getElementById("clickCounter").innerHTML = clickCount; clickBoost = true; } else{ console.log("You didn't bought 2x Clicks.") } } if (clickBoost == true) { document.getElementById("clickButton").onclick = function () { clickCount += 2; document.getElementById("clickCounter").innerHTML = clickCount; } } }
about 4 years ago · Juan Pablo Isaza Report
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!