Simon Game, Javascript settimeout and animation
<p>Can anybody help me to simulate animation of four div tags?
Simply for loop should wait until opacity of div tags change in 1 second. </p>

<pre><code>function animateDiv(ar) { // ar contains div tag indexes. ex:[0,3,2,3,1,0,1,2,3]
    for (var i = 0; i &lt; ar.length; i++) {
        var ind = "";

        if (ar[i] == 0) ind = ".red";
        else if (ar[i] == 1) ind = ".blue";
        else if (ar[i] == 2) ind = ".yellow";
        else if (ar[i] = 3) ind = ".green";
        var ok = false;
        setTimeout(function () {
            $(ind).css('opacity', 1);
            console.log("waiting " + " index: " + i);
            ok = true;
        }, 1000);

        if (ok == true) {
            $(ind).css('opacity', 0.7);
            console.log("Done!");
        }

    }
}
</code></pre>

<p><a href="https://jsfiddle.net/z8y2v5u1/" rel="nofollow">https://jsfiddle.net/z8y2v5u1/</a></p>