Вопрос Измениие программу по моему условию в html

Регистрация
26 Ноя 2012
Сообщения
68
Репутация
0
Спасибо
0
Монет
0
Мне нужно чтобы программа выводила всё слова с одинаковым числом букв в слове

<form>

Введите предложение:

<input type="text" id="inputSentence">

<input type="button" value="Найти" onclick="findLongestWord()">

</form>



<script>

function findLongestWord() {

var sentence = document.getElementById("inputSentence").value;

var longestWord = "";



sentence.split(" ").forEach(function(word) {

if (word.length > longestWord.length) {

longestWord = word;

}

});



var message = "Самое длинное слово в предложении: " + longestWord;

alert(message);

}

</script>
 
function findLongestWord() {
let words = document.getElementById('inputSentence').value.split(' ');
let lng = Math.max(...words.map(w => w.length));
alert('Самые длинные слова в предложении: ' +
(words.filter(w => w.length === lng).join(' ')));
}
 
...................................
304651920_647baadf996bb0bfc9fe7ac94e6f5779_800.png

 
Назад
Сверху