Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda