How would you make pre-written text appear when typing something?

StackOverflow Solution

by Atif Hassan

HTML

<textarea id="text" style="width:300px;height:200px" value="" onkeypress="myFunction(); return false;"></textarea>

JavaScript

var pre_msg = ["The brown", "Fox jumped", "over the well with", "or wait", "was it a pond", "well", "that's beside the point now.", "Oh and not to forget", "HACKED !"]

function myFunction() {
  var index = Math.floor(Math.random() * pre_msg.length);
  document.getElementById("text").value +=pre_msg[index]+" ";
}