$.get('txt/messages.txt', function(txt) { var lines = txt.responseText.split(" "); var randLineNum = Math.floor(Math.random() * lines.length); return lines[randLineNum]; // random line from the text file });