JSFiddle - React, Tailwind, and code Playground

by Dogbert

HTML

<textarea id="comment" rows=10 cols=80></textarea>

CoffeeScript

options = ["mi3", "xiaomi", "samsung", "apple", "iphone", "galaxy"]
regexp = new RegExp(" (" + options.join("|") + ")$", "i")

$("#comment").keypress (e) ->
  return unless e.which == 32
  text = $(this).val()
  if regexp.test text
    random = options[~~(Math.random()*options.length)]
    $(this).val text.replace(/\w+$/, random)