<form>
<textarea></textarea>
<textarea readonly></textarea>
<button type="submit">Кнопка</button>
</form>
<style>
form * {
display: block;
margin-bottom: 5px;
width: 100%;
box-sizing: border-box;
}
</style>
<script>
var form = document.querySelector('form'),
textarea = form.querySelector('textarea'),
resultContainer = form.querySelector('textarea[readonly]'),
button = form.querySelector('button');
function getMiddleCharOfWord(word) {
var position = Math.floor(word.length / 2);
if (word.length % 2 === 0) {
return word.charAt(position - 1) + word.charAt(position);
}
return word.charAt(position);
};
form.addEventListener('submit', function (e) {
e.preventDefault();
var words = textarea.value.split(' ').filter(function (word) {
return word.length > 2;
}).map(function (word) {
return `${word} (${getMiddleCharOfWord(word)})`;
});
resultContainer.value = words.join(' ');
});
</script>