Augustin Dennis
Augustin Dennis

Reputation: 1

Not inserting element on call inserts after the entire execution

function loadval() {
  r = Math.floor(Math.random() * load.length);
  console.log(r);
  for (let i = 0; i < 9; i++) {
    for (let j = 0; j < 9; j++) {
      var set = (i + 1) * 10 + j + 1;
      var x = document.getElementById(set);
      x.value = load[r][i][j];
      console.log(load[r][i][j]);
      sleep(25);
    }
  }
}

The element is not inserted one by one after the delay, all the elements are set after the whole function gets executed.

Upvotes: 0

Views: 39

Answers (1)

ironCat
ironCat

Reputation: 161

why not use setInterval or setTimeout instead sleep(25)?

// repeat at 2 second intervals

let timerId = setInterval (() => loadval(), 2000);

// stop output after 10 seconds

setTimeout (() => {clearInterval (timerId); alert ('stop');}, 10000);

Upvotes: 1

Related Questions