Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!