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

182
Vistas
How can I manipulate the DOM after a given time?

How can I manipulate the DOM after some delay? I want the background to change to green and the score update once the player guesses right. Then after some seconds, I want the background to return to the initial state and hidden number which I set to be a randomly generated number to change. Everything worked out well by using setInterval but it turns out that the hidden number continues to regenerate within the given time.


//This is the function for the timer
function correctDefault() {   
        setInterval(() => {
            document.querySelector('body').style.backgroundColor= '#222'
            document.querySelector('.number').style.width= '15rem'
            document.querySelector('.number').textContent = '?'
          // secretNumber = Math.trunc(Math.random() * 20) + 1;
           document.querySelector('.number').textContent = secretNumber
        }, 3000);
    }


//And this is the condition

  else if (guess === secretNumber) {

            if (score !== 50) {
                document.querySelector('body').style.backgroundColor= '#60b347'
        
                displayMessage('🎉 Correct Number!')
                score++

                document.querySelector('.number').style.width= '17rem'
                document.querySelector('.number').textContent = secretNumber
                document.querySelector('.score').textContent = score;
                correctDefault()
            }
            
            
           else{
                displayMessage('👏 You Won the Game')
                document.querySelector('.highscore').textContent = score;
                document.querySelector('body').style.backgroundColor= 'rgb(180, 245, 0'
                
                document.querySelector('.number').textContent = guess
            }      
        
    
    }
about 4 years ago · Juan Pablo Isaza
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