Inside getNum
, you’re directly invoking the getNum
function, causing the stack to exhaust. Replace the function call getNum()
with the function reference getNum
:
function getNum() // Gets triggered by page load so innerHTML works
{
num += 7; // Increase and assign variable
document.getElementById('counter').innerHTML = num;
setTimeout(getNum, 4000); // <-- The correct way
}
Link to documentation of setTimeout
.