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

240
Vistas
code in a code block were not executed in order

please help the newbie that just started the js, I have a function in the game that checks for a false condition and then restarts the game. For some reason, the restart() function was always called before the other two lines, that query the HTML and shows the game result.

function checkResult(id) {
    if (!combo.includes(id)){
        document.querySelector('body').classList.add('game-over');
        document.getElementById("title").innerHTML = "You lost, Press start button to restart";
        restart();
    }
function restart() {
    alert("game started")
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's likely that restart is not being called first. You can verify this using the chrome debugging tools or using console.log to print out the order of operations.

What's going on is that your DOM changes are not visually represented by the browser until the next repaint. Repainting happens in between synchronous blocks of code. restart is synchronous, so you see the alert before you see the DOM changes.

If you want to wait for the browser to repaint, I believe you can make use of the requestAnimationFrame API (see this SO answer).

This is all assuming that your code missing brackets and such is just a copy-paste error. Do ensure your syntax is correct.

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