// Выбираем случайное слово из массива var words = ["программа", "процессор", "прекрасный", "робот"]; var word = words[Math.floor(Math.random() * words.length)]; // Неугаданные буквы var remainingLetters = word.length; // Попытки var remainingAttempt = 3; // Создаем массив ответов и заполняем его var answerArray = []; for (var i = 0; i < word.length; i++) { answerArray[i] = "_"; }; // Основной цикл программы while (remainingLetters > 0 && remainingAttempt > 0) { alert('Текущее слово : ' + answerArray.join(" ")); var guess = prompt("Угадайте букву или нажмите отмена для выхода из игры."); guess = guess.toLowerCase(); console.log(guess); if (guess === null) { break; } else if (guess.length !== 1) { alert("Пожайлуста, введите только одну букву."); } else { for (var j = 0; j < word.length; j++) { if (word[j] === guess) { if (answerArray[j] === '_') { answerArray[j] = guess; remainingLetters--; alert("Вы угадали букву!"); } else { alert("Вы уже угадали эту букву!"); } } else { remainingAttempt--; alert('Попыток осталось ' + remainingAttempt); break; } } } } alert('Результат : ' + answerArray.join(" ")); alert("Конец игры! Было загадано слово " + word); I can not understand why in the example the condition if (word[j] === guess) becomes equal to false , although the letter is entered which is in the word and goes to its else . If you remove the else , then everything works as it should. Help me to understand.
===replaced by==? - ArchDemon