mercredi 2 novembre 2016

Constructing a Win Check with For Loop and If Else?

My Code is below It is currently set to run on the click of a button. How do I get it to check itself without clicking the button?

<button onClick="checkWin()">Have you won?</button>



function checkWin() {

        var incorrect = 0;

        for(i =0; i < 25; i++) {

        var check = document.getElementById("cell" + i).style.backgroundColor;
        


    if(check == "yellow") {
                    incorrect++;
                } }

        if (incorrect == 0) {
            alert("You Win!");
        } else {
            alert("You haven't won yet!")
        } }

Aucun commentaire:

Enregistrer un commentaire