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

148
Views
How to make user click numbers in divs in ascending order?

I need to create a game with pure JS. I generate 16 numbers in 16 divs in an random order and the user is supposed to click those numbers in 10 seconds in ascending order if the user fails the game ends.

How to make sure that the next div user clicks contains number 2?

var divs = document.querySelectorAll("div");

function generisi() {
  let niz = new Set()
  var i = 0;

  while (niz.size < 16) {
    niz.add(Math.floor(Math.random() * 16) + 1);
    console.log(niz);
  }

  niz = Array.from(niz);

  for (var j = 0; j < divs.length; j++) {
    divs[j].innerHTML = '<p class="broj">' + parseInt(niz[j]) + '</p>';
  }
}

for (var i = 0; i < divs.length; i++)
  divs[i].addEventListener("click", function() {
    for (var j = 0; j < divs.length; j++) {
      if (divs[j].getElementsByTagName("p")[0].innerText == 1) {
        divs[j].getElementsByTagName("p")[0].innerText = ""
      }
    }
  })

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!