JSFiddle - React, Tailwind, and code Playground
HTML
<style type="text/css">
* { padding: 0; margin: 0; }
#wrapper { margin: 0 auto; width: 650px; }
#outputWindow { position: relative; float: left; top: 0px; left: 0px; width: 100%; height: 100%; min-height: 100%; overflow-x: hidden; overflow-y: auto; border: 1px solid black; }
#inputWindow { position: relative; left: 0px; bottom: 0px; float: left; border: 1px solid black; }
</style>
</head>
<body>
<div id="wrapper">
<div id="outputWindow"></div>
<input type="text" id="inputWindow"></input>
<input type="submit" id="sendButton" />
</div>
JavaScript
$(document).ready(function() {
var n = prompt('What is your name?');
var o = $('#outputWindow');
var i = $('#inputWindow');
var s = $('#sendButton');
var r = 0;
//arrays
var helloInputArray = ['hi','hello','hey','yo','word'];
var helloOutputArray = ['hello '+n+'<br />','yo '+n+'!<br />','word up '+n+'!<br />','Greetings '+n+'<br />','Moshi moshi '+n+'<br />'];
var byeInputArray = ['bye','goodbye','cheerio','piss off','sod off'];
var byeOutputArray = ['bye '+n+'<br />','goodbye '+n+'!<br />','you should sod off '+n+'!<br />','bi bi '+n+'<br />','fine! '+n+'<br />'];
//fire send events
$(s).click(function() {
runAI();
});
$(i).keydown(function(e) {
if (e.keyCode == 13) {
runAI();
}
});
function runAI() {
if (i.val().length > 0) {
if ($.inArray(i.val(), helloInputArray) > -1) {
r = Math.floor(Math.random()*4);
o.html(o.html()+helloOutputArray[r]);
i.val('');
i.focus();
} else if ($.inArray(i.val(), byeInputArray) > -1) {
r = Math.floor(Math.random()*4);
o.html(o.html()+byeOutputArray[r]);
i.val('');
i.focus();
} else {
o.html(o.html()+"I don't know what that means...<br />");
i.val('');
i.focus();
}
}
}
i.focus();
});