You create a new LOCAL variable with the name showNo, this does not apply to the GLOBAL variable with the name showNo.
It is very bad to use global variables, I advise wrapping this inside an anonymous function
I think this is what you want to do:
(function() {
var showNo = 1;
window.setInterval(function() {
console.log(showNo);
if( showNo >== 1 && showNo <== 4 ) {
showNo++;
} else if( showNo === 5 ) {
showNo = 1;
} else {
showNo = 2;
}
}, 500);
})();
source
share