Long story short: If the interval count exceeds 5 the code should clear the interval, stopping it from executing the function every second. But this doesn't seem to work.
HTML
<div id='feedback'></div>
JavaScript / jQuery
window.intervalcount = 0;
var interval = setInterval(function () {
intervalcount += 1;
$("#feedback").text(intervalcount);
}, 1000);
if(intervalcount > 5) {
clearInterval(interval);
}
But I can't seem to find the issue...
So currently, your code is going to run something like this order:
Placing the:
inside the interval's function will perform your desired behavior.