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

183
Vistas
Whenever trying to toggle, it always switches to true no matter what way I try to toggle

Logs
enter image description here

Code that displays the logs
enter image description here

So, I have an HTML button hooked up to run the function shown in the code above, and I've tried many ways like using different toggle functions such as bool = bool ? false : true; but none work. I've tried to insert the hideToggled = !hideToggled in other places, like both the if functions, or below the if functions, but neither seems to work. Any help would be extremely appreciated!

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

0

You are assigning your variable true/false value in the if blocks

if (hideToggled = true)

will result in hideToggled to be assinged the value true

Check out the working code below:

let hideToggled = false
let hideButtonText = ''

function toggleHideShow() {
  hideToggled = !hideToggled

  if (hideToggled) {
      hideButtonText = 'Show'
  } else {
      hideButtonText = 'Hide'
  }
}

toggleHideShow()
console.log(hideToggled, hideButtonText)
toggleHideShow()
console.log(hideToggled, hideButtonText)
toggleHideShow()
console.log(hideToggled, hideButtonText)
toggleHideShow()
console.log(hideToggled, hideButtonText)

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