lundi 26 février 2018

Variable Returns False, but if statement doesn't acknowkedge it

I have an if statement that is supposed to execute code if a variable returns false, but even though I have checked and made sure the variable returns false, the code does not execute. Here is the code:

function letterCheck() {
            var wordToGuess = puzzle;
            var letterToGuess = guess;
            console.log(letterToGuess);
            matched = false;
            for (x = 0; x < wordToGuess.length; x++) {
                if (letterToGuess === wordToGuess[x]) {
                        console.log('Your guess was correct!');
                        console.log('You have', 6 - parts, 'incorrect guesses remaining');
                        blanks[x] = letterToGuess;
                        console.log(blanks);
                        var fillBlank = '';
                        for (y = 0; y < blanks.length; y++) {
                                fillBlank += blanks[y];
                        }
                        document.getElementById('puzzle').innerHTML = fillBlank;
                        matched = true
                        win++
                        if (win === puzzle.length) {
                            setTimeout(() => alert("You win!"), 100)
                        }
                        break;
         
                }

        }
    }


//this is the if statement that is not working
if (this.matched === false) {
        console.log("Your guess was incorrect!");
        parts++;
        graphics[parts - 1]();
        console.log('You have', 6 - parts, 'incorrect guesses remaining');
}

Aucun commentaire:

Enregistrer un commentaire