[Javascript] Hello

debt debt at fannullone.us
Thu Aug 10 10:57:08 EDT 2017


> On Aug 8, 2017, at 3:05 PM, Richard Bullington-McGuire via Javascript <javascript at obscure.org> wrote:
> 
> It is super-quiet, but technically alive. Do you have a question?

	Yes.  I'm new to JavaScript and I'd like to wrap some code in a function but can't figure out how to do it.  Here's the (jQuery?) code:

$.get('phrases.txt', function (data) {
    var lines = data.split('\n');
    var randLineNum = Math.floor(Math.random() * lines.length);
    var verse = lines[randLineNum];
    return verse;
});

	This code returns a random line from a text file.  I want the output in multiple places in my script, so I need to either wrap it in a function or populate a global variable.  I've tried quite a few different ways to do it, but none were successful.

	Any help would be appreciated.

Thanks,
Frank


More information about the Javascript mailing list