0

For some reason, my code doesn't appear to run in the background if the tab's not open.

Here is the code:

num = 0;

window.setInterval(function() {
  num = num + 1;
  document.getElementById('num').innerHTML = num;
}, 10);
<html>

<head>
  <title>Space...</title>
</head>

<body>
  <span id="num">0</span>
  <script src="main.js"></script>
</body>

But it is working on a separate game I've made, i.e. it does continue running if the tab's not open.

I've searched the web and Stack Overflow for answers, but I haven't been able to find any. I don't know why this is happening, so any help would be much appreciated. Thanks in advance!

William Jones
  • 809
  • 2
  • 11
  • 29

0 Answers0