mercredi 26 avril 2017

JavaScript - an array in if statement

I really need some help with this one, I've been struggling a lot trying to crack the example down on my own for way too long.. the whole issue is that I have an array that includes 15 pictures added by push property & createImage function, the problem though is that I've absolutely no idea how I could use the image in an if-statement like so:

if (check both if the image displayed is the first image within the array and answer equals 'x') return that's a good answer that's a good answer } else (in case if either the image isn't the first one or answer doesn't equal 'x' return that's not a good answer

So far I've achieved the following, unfortunately enough the program omits the rule regarding the array

var answer = document.getElementById("answer");
var image = newArray[0];

    function check() {
        if (newArray[0] == true && answer.value == "C") {
            window.alert("that's a good answer");
        } else if (newArray[0] == true && answer.value == "c") {
            window.alert("that's a good answer as well");
        } else {
            window.alert("that's unfortunately not a good answer");
        }
    }

Thanks in advance for any form of help

Aucun commentaire:

Enregistrer un commentaire