There is such a script to sort the text entered by the user:
var words = prompt('Введите произвольный текст: ').split(' '); function sortingWords(words) { for (var i = 0; i < words.length-1; i++) { for (var j = 0; j < words.length-1-i; j++) { if (words[j+1] < words[j]) { var t = words[j+1]; words[j+1] = words[j]; words[j] = t; } } } console.log(words) } In general, I can’t figure out how to make a button click (onclick = ""), first ask the text, then transfer the entered text to the function, well, output the sorted array
wordsis an array of strings, not a string - Grundyvar words = prompt('Введите произвольный текст: ').split(' ');This thing will make an array of words. Why I clarify, suspicions creep in that the author wants to sort them by word length. - user200141