lundi 19 février 2018

How do I use an array in a if parented by a for loop in java?

I am trying to loop through the colors in my array using a for loop and IF the array gets to the 'orange' then have it break the loop. Here is my code(I'm only two weeks into coding, please educate me - Also if you can find a solution not only in javascript but jQuery too that would be great! help my spirit ) :

var button = document.querySelector("button")
var gifs = ['purple', 'yellow', 'orange'];

button.addEventListener("click", function(){
    for (i = 0; i < gifs.length; i++) {
        // document.body.style.background = gifs[i];
        if ( gifs.length[2] = true) {
            console.log("its GOOD");
            else {
                console.log("ITS NOT GOOD");
            }
        }
    }
});

Aucun commentaire:

Enregistrer un commentaire