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

160
Views
Estoy haciendo un simple juego de clicker en javascript pero una de las funciones no parece estar funcionando. ¿Puede alguien ayudarme a arreglarlo?

Tengo este problema con un juego de clicker que tengo. Entonces, básicamente, lo que estoy tratando de hacer que haga el juego es que una vez que el jugador haya obtenido 200 puntos, el jugador tiene la capacidad de desbloquear o revelar los nuevos clickers. Pero por alguna razón, incluso si tiene 0 puntos, puede desbloquear los nuevos clickers. ¿Puede alguien ayudarme con esto? Gracias

Código de clic de Javascript:

 let totalclicks = 0; let superclicker1 = document.getElementById("superclicker1") let pointsEl = document.getElementById("points-el") function clicker1() { totalclicks = totalclicks + 5; pointsEl.textContent = "Total Points: " + totalclicks }

Javascript desbloquear nuevo código clicker

 function rebirth() { if (totalclicks >= 200) { } else if (superclicker1.style.display === "none") { superclicker1.style.display = "block"; } else if (superclicker1.style.display = "none") { } else { alert("Need 200 points to win.") } }

Html para el clicker

 <p id="points-el">Total Points: </p> <button onclick="clicker1()">Five Point Per Click </button>

Html para la función que desbloquea los siguientes clickers:

 <button id="superclicker1" onclick="superclicker10()">Rebirth </button>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

  1. Sugiero usar nombres más representativos para las variables de sus elementos. Hace que su código sea más legible.

  2. Creo que quieres llamar a rebirth desde el botón de renacimiento.

  3. Su declaración if debe estar anidada. "Si el total es igual o superior a 200, cambie el estilo según la condición anidada; de lo contrario, avise el mensaje.

 let totalclicks = 0; const pointsEl = document.getElementById('points-el'); const rebirthEl = document.getElementById('rebirth'); function addFive() { totalclicks = totalclicks + 5; pointsEl.textContent = "Total Points: " + totalclicks; } function superclicker() { // Missing code } function rebirth() { if (totalclicks >= 200) { if (rebirthEl.style.display === 'none') { rebirthEl.style.display = 'block'; } else { rebirthEl.style.display = 'none'; } } else { console.log("Need 200 points to win.") } }
 <p id="points-el">Total Points: </p> <button onclick="addFive()">Five Point Per Click</button> <button id="rebirth" onclick="rebirth()">Rebirth</button>

about 4 years ago · Juan Pablo Isaza Report

0

Esta linea es donde esta el problema

 } else if (superclicker1.style.display = "none") {

Single = se utilizan para la asignación, no para los controles condicionales. Probablemente desee == o === para una verificación estricta de tipos.

Dado que está utilizando la asignación = , entonces la declaración else if siempre se resolverá como true . Así que tu lógica se ve así:

 if (false) { } else if (false) { } else if (true) { // this block will always be triggered } else { }

Tal vez estabas buscando algo como:

 if (totalclicks >= 200) { if (superclicker1.style.display === "none") { superclicker1.style.display = "block"; } else { superclicker1.style.display = "none"; } } else { alert("Need 200 points to win.") }
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!