Tell me why without if-and the timer works fine, and with it - it does not start at all?
var sum = 0; var first = 0; var second = 0; function additionFunction() { document.getElementById('example').innerHTML = ""; document.getElementById('timerAddition').innerHTML = ""; first = Math.floor(Math.random() * 10); second = Math.floor(Math.random() * 10); if (right >= 1) { first = Math.floor(Math.random() * 15); second = Math.floor(Math.random() * 15); } sum = parseInt(first + second); document.getElementById('example').innerHTML = first.toString() + " + " + second.toString(); document.getElementById('timerAddition').innerHTML = sum + Math.floor(Math.random() * 8); timerAddition(); } var timerID = setInterval(timerAddition, 1000); function timerAddition() { var obj = document.getElementById('timerAddition'); obj.innerHTML--; if (obj.innerHTML < sum.innerHTML) { clearInterval(timerID); } }
sumsuddenly innerHTML come from? - DaemonHK