var x = 0;
var interval = setInterval(function() {
    alert("Loop iteration #" + x++);
    if(x==6) {
        var x = 0;
    }
}, 500);

This code prompts "#NaN" with each message, but I expected it to be going 1, 2, 3, 4, 5 and then back to 1, 2, 3, 4, 5. For endless loop.

Remove the var key word from line 5. You don't want to to be specifying a new version of X, just reset the existing x variable.

You solved it. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.