JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container" id="container">
<h1 id="finalWord"></h1>
<input type="text" id="searchInput" placeholder="Жаргонизм">
<button id="submitBtn">Найти жаргонизм</button>
</div>
JavaScript
$(function () {
var words = {
'девушка': ['чикса', 'тёлка', 'чувиха'],
'замечательный': ['чумовой', 'отпадный', 'классный']
};
var App = {
init: function () {
this.cacheElements();
this.bindEvents();
},
cacheElements: function () {
this.$container = $('#container');
this.$finalWord = this.$container.find('#finalWord');
this.$searchInput = this.$container.find('#searchInput');
this.$submitBtn = this.$container.find('#submitBtn');
},
bindEvents: function () {
this.$submitBtn.on('click', this.findWord.bind(this));
},
findWord: function (e) {
var word = this.$searchInput.val().trim(),
random,
f,
v;
if (!word) return;
for (var i in words) {
if (i === word) {
random = Math.floor(Math.random() * words[i].length);
this.$finalWord.text(words[i][random]);
}
}
e.preventDefault();
}
}
App.init();
});