JSFiddle - React, Tailwind, and code Playground

by winns

HTML

<textarea></textarea>

CSS

textarea {
    width: 300px; height: 100px;  
}

JavaScript

$(document).ready(function(){
    
    var dialog = {
        input: $('textarea'),
        questionAnswer: {
            'who ?' : 'man',
            'why ?' : 'dunno',
            'when ?' : '00:00',
            'test' : 'just a test'
        },
        checkQuestion: function(){
            var answer = false;
            
            for (var question in this.questionAnswer) {
                if ( this.input.val() === question ) {
                    answer = this.questionAnswer[ question ];
                    break;
                }
            }
            
            if (answer != false) {
                this.input.val( answer );
            } else {
                this.input.val( 'unknown question' );
            }
        }
    }
    dialog.input.on('keypress', function(e){
        // on 'enter'
        if (e.which == 13) {
            e.preventDefault();
            dialog.checkQuestion();
        }
    });

});