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

94
Vistas
¿Cómo anularía la ejecución de una función llamada dentro de una función de controlador de eventos una vez que se cumple una condición en JavaScript?

Estoy trabajando en una tarea para la escuela y tengo que trabajar. El objetivo era mostrar Pokémon en la página y hacer que la pelota se sacudiera como si algo intentara salir de ella. Las imágenes tiemblan, pero no estoy seguro de cómo detenerlas una vez que se alcanza la imagen final con lo que tengo hasta ahora:

 class Eevee extends Pokemon { constructor (evolutionPath, evolutionStage) { super (evolutionPath = [ "images/pokeball.png", "images/eevee/eevee0.png", "images/eevee/eevee1.png", "images/eevee/eevee2.png", "images/eevee/eevee3.png", "images/eevee/eevee4.png", "images/eevee/eevee5.png", "images/eevee/eevee6.png", "images/eevee/eevee7.png", "images/eevee/eevee8.png" ], evolutionStage) this.evolutionStage = 0 } evolve = function () { main.append(this.image) this.image.setAttribute(`src`, `${this.evolutionPath[0]}`) this.image.addEventListener("click", function () { this.toggleShake(this.image) let evolveChance = Math.floor(Math.random( ) * 5 + 1) if (evolveChance === 1){ if (this.evolutionStage === 0){ this.evolutionStage = 1 this.image.setAttribute(`src`, `${this.evolutionPath[this.evolutionStage]}`) this.evolutionStage = Math.floor(Math.random() * ((this.evolutionPath.length)- 2) + 1) return this.image } else if (this.evolutionStage <= this.evolutionPath.length - 1 && this.evolutionStage >= 2){ this.image.setAttribute(`src`, `${this.evolutionPath[this.evolutionStage]}`) return this.image } }}.bind(this)) }.bind(this) } let eeveeA = new Eevee () eeveeA.evolve()

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Pude refactorizar mi instrucción if anterior y hacer que funcione:

evolucionar = function () { main.append(this.image) this.image.setAttribute( src , ${this.evolutionPath[this.evolutionStage]} ) this.image.addEventListener("click", function () {

 let evolveChance = Math.floor(Math.random( ) * 5 + 1) ***if(this.evolutionStage === 0 || this.evolutionStage === 1) { this.toggleShake(this.image) }*** if (evolveChance === 1){ if (this.evolutionStage === 0){ this.evolutionStage = 1 this.image.setAttribute(`src`, `${this.evolutionPath[this.evolutionStage]}`) this.evolutionStage = Math.floor(Math.random() * ((this.evolutionPath.length)- 1) + 2) return this.image } else if (this.evolutionStage <= this.evolutionPath.length - 1 && this.evolutionStage >= 2){ this.image.setAttribute(`src`, `${this.evolutionPath[this.evolutionStage]}`) return this.image } }}.bind(this))

}.bind(esto) }

about 4 years ago · Santiago Gelvez 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