When entering a letter that is in the word variable, according to the idea, if there is no such letter, then it should display a message, that there is no such letter .
But for some reason this message is displayed even if this letter is there, why?
If you remove the last condition, it works fine
https://jsfiddle.net/xqqbyexb/
var word = 'ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ°'; var answerArray = []; for (var i = 0; i < word.length; i++) { answerArray[i] = "_"; } var remainingLetters = word.length; while (remainingLetters > 0 ) { alert(answerArray.join(" ")); var guess = prompt("Π£Π³Π°Π΄Π°ΠΉΡΠ΅ Π±ΡΠΊΠ²Ρ, ΠΈΠ»ΠΈ Π½Π°ΠΆΠΌΠΈΡΠ΅ ΠΡΠΌΠ΅Π½Π° Π΄Π»Ρ Π²ΡΡ
ΠΎΠ΄Π° ΠΈΠ· ΠΈΠ³ΡΡ."); if (guess === null) { // ΠΡΡ
ΠΎΠ΄ΠΈΠΌ ΠΈΠ· ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ ΡΠΈΠΊΠ»Π° break; } else { for (var j = 0; j < word.length; j++) { if(answerArray[j] === guess){ alert('Π’Π°ΠΊΠ°Ρ Π±ΡΠΊΠ²Π° ΡΠΆΠ΅ Π΅ΡΡΡ') } else if(word[j] === guess) { answerArray[j] = guess.toLowerCase(); remainingLetters--; } else if(word[j] != guess){ alert('Π’Π°ΠΊΠΎΠΉ Π±ΡΠΊΠ²Ρ Π½Π΅ΡΡ'); break; } } } }